我的代码中没有红色标记。它可以运行,但是什么都不显示?
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()或未将menu()分配给诸如displayMenu = MENU CODE 之类的变量。我不确定如何正确地添加或传递该变量而不破坏它
答案 0 :(得分:1)
如果您已逐字复制并粘贴了代码,则问题是您的main()
函数缩进不正确。取消缩进main()
行。
缩进main()
时,它成为函数menuInput()
的一部分,结果在Python的 actual main
中没有任何运行({ {1}}。