繁体   English   中英

如何修复我的代码以正确显示我的菜单?

[英]How can I fix my code to properly display my menu?

我的代码中没有危险信号。 它运行但它不显示任何东西?

def main():
  menuInput()

def menu():
  print('''
  Welcome! Please make a choice from the following menu

  1. Select a year and display available data
  2. Review averages by year range
  3. Select a date range and show highest temperature
  4. Select a date range and show lowest temperature 
  5. Get total rainfall for a selected year range
  6. blank
  7. blank
  8. See this menu again
  9. QUIT the program
''')


def menuInput():
  while True:
    menu()
    try:
      userChoice=int(input('Please make a selection: '))
      if userChoice > 9:
        print('Please enter a number less or equal to 9')
      elif userChoice <= 0:
            print('Please enter a number greater than 0')
      elif userChoice == 1:
            print('Good')
      elif userChoice == 2:
            print('Good')
      elif userChoice == 3:
            print('Good')
      elif userChoice == 4:
            print('Good')
      elif userChoice == 5:
            print('Good')
      elif userChoice == 6:
            print('Good')
      elif userChoice == 7:
            print('Invalid Choice')
      elif userChoice == 8:
        print('Good')
      elif userChoice == 9:
        print('Program Exiting!')
      else:
        print('Invalid Choice')
        continue
    except ValueError:
      print('Please enter a whole number instead')
      continue
  main()

我想假设这是因为 menu() 要么没有被正确调用,要么没有被分配给像 displayMenu= MENU CODE这样的变量。 我不确定如何正确 go 关于添加或传递该变量而不破坏它

如果您已逐字复制并粘贴代码,那么问题是您的main() function 缩进不正确。 取消缩进main()行。

当您缩进main()时,它成为 function menuInput()的一部分,因此在 Python 的实际main中没有运行任何内容( if __name__ == "__main__")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM