Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My menu loop isn't working and I don't know why

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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): "))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading