rage / programming-24

43 stars 28 forks source link

bug in "Dictionary stored in a file" programming exercise #30

Open abuakramGit opened 4 months ago

abuakramGit commented 4 months ago

FAIL: DictionaryFileTest: test_1_exit_only Program should output two lines with input 3 now the output is Bye!

This is wrong, since output sample says: Function: 3 Bye!

FAIL: DictionaryFileTest: test_2_remove_add_words_and_exit Program should output two lines with input 1 auto car 3 now the output is Dictionary entry added Bye!

This is a bug too, since when ever a word is added to dictionary, "Dictionary entry added" should be printed out

following my code:

''' while True:

dictionary = []
with open('dictionary.txt') as file:
    for line in file:
        line = line.strip()
        dictionary.append(line)

function = int(input("1 - Add word, 2 - Search, 3 - Quit\nFunction: "))
if function == 1:
    finnish = input('The word in Finnish: ')
    english = input('The word in English: ')
    text = f'{finnish} - {english}'
    if text in dictionary:
        continue
    else:
        dictionary.append(f'{text}')
    with open("dictionary.txt", "a") as file:
        for line in dictionary:
            file.write(f'{line}\n')
    print("Dictionary entry added")
elif function == 2:
    term = input('Search term: ')
    for dic in dictionary:
        if term in dic:
            print(dic)
else:
    print('Bye!')
    break

'''

Row-row-row-your-boat commented 3 months ago

Just commenting to confirm these two bugs. Spent way too much time trying to figure it out. Haven't found a way around both bugs for part 6 exercise 16 "Dictionary stored in a file". But for the bug on part 6 exercise 11 "Diary", you can just type,

print("Bye!) print("Bye!)

and it will mark as passed.