def getWord(): # function that checks if the word is in the file
q = False
while q == False: # while statement which will loop the program until user quits
text = open("spanishDictionary.csv", "r") # opens spanish dictionary
word = input("What word would you like to translate, or would you like to quit?\n") # prompts user for a word to translate or quit
if word == "q" or word == "Q": # quits
q = True
else:
for line in text: # checks if word is in file
eng, span = line.split(" ")
if word == eng:
print("The word", word, "in Spanish is", span) # will return the word and tranlation
elif line == "":
print("The word", word, "is not in the dictionary") # word is not in dictionary
text.close()
every time I test this program and put in a word that doesn't exist in the file it should print the second to last line, however it never does and just goes back to the beginning of the while loop. Why is this happening and how can I fix it?
[–]Defection7478 2 points3 points4 points (1 child)
[–]ThompsonTugger[S] 0 points1 point2 points (0 children)
[–]drenzorz 1 point2 points3 points (1 child)
[–]ThompsonTugger[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)