私は "0"を入力したときに私のプログラムが終了しない理由を知ろうとしています。メニューをもう一度やり直すだけです。Pythonプログラムが終了しません
def menu():
print('\n\n\n\n')
print('List Processing Program Menu')
print('0 to exit')
print('1 to view data')
print('2 to append data')
while(1):
try:
choice = -1
while(choice < 0 or choice > 2):
choice = int(input('Please enter a valid number choice '))
break
except ValueError:
print('Enter an integer number for your menu selection')
return choice
def main():
while(1):
choice = menu()
if(choice == 0):
break
main()
あなたの 'return'ステートメントは、あなたがそれを得る前に'中断する 'whileループの中にあるので、 'menu'から値が返されません。したがって、 'main'の内部では、常に' None'が選択されます。 'return'ステートメントをインデントしないと、これは期待どおりに動作します。 – Suever