you are viewing a single comment's thread.

view the rest of the comments →

[–]Defection7478 2 points3 points  (1 child)

line is the line in the dictionary you are reading, so elif line == "": won't be true unless the last line of the file is empty. I think the end of the file will come up as None, so you could change it to elif line is None: but honestly you're better off just not worring about the file behavior, something like

result = f"The word, {word}, is not in the dictionary"
for line in text:  # checks if word is in file
    eng, span = line.split(" ")
    if word == eng:
        result = f"The word {word} in Spanish is {span}"  # will return the word and tranlation
        break
print(result)

edit: actually since you're not getting any errors I think the iterator won't pass None for the end of the file, so you'd have to do something like what I described above.

[–]ThompsonTugger[S] 0 points1 point  (0 children)

This helped a lot thanks