I’m writing code for a project and am just finishing up the menu, where there are 5 options and the user inputs a number to select said option. Here’s my code:
display_menu(True)
command = input("Enter a number (0 to exit): ")
while command != 0:
if command == 1:
namefile = input("Enter word list filename: ")
wordlist = make_list(namefile)
print('Word list is loaded.')
elif command == 2:
namefile = input('Enter movie review filename:')
moviedict = make_dict(namefile)
print('Movie reviews are loaded.')
elif command == 3:
searchword = input('Enter a word to search: ')
count1, score1 = search_word(searchword)
print(searchword + ' appears ' + count1 + ' times')
print('The average score for the reviews containing the word terrific is: ' + score1)
elif command == 4:
print_lists(list, list_scores)
elif command == 5:
pass
display_menu(True)
command = input("Enter a number (0 to exit): ")
it definitely prints the list but when I enter a command input it doesn’t actually work. If anyone has any ideas let me know ASAP because it’s due tonight lol. Cheers and thanks in advance.
>Solution :
command is a string returned by input, and you’re comparing to an int. You need to explicitly convert that string to an int.
command = int(input("Enter a number (0 to exit): "))