之前停止Python中退出程序的方法我使用以下代碼構建了一個簡單的Python程序,該程序從用戶獲取輸入。如果執行命令
Name = raw_input('Enter your name: ')
Age = raw_input('Enter you age:')
Qualifications = raw_input('Enter you Qualification(s):')
A = raw_input()
print "Hello" +'.'+ "Your Name is " + Name + ". " + "Your Age is " + Age + ". " + "Your Qualification(s) is/are:" + Qualifications + "."
print "If the above data is correct, type yes. If not, type no. Typing no will restart he program and make you write the form again." + A
if A in ['y', 'Y', 'yes', 'Yes', 'YES']:
print 'Thanks for your submission'
if A in ['No' , 'no' , 'NO' ,'n' , 'N']:
reload()
程序在if命令之前完成。
代碼在「if」命令之前絕對沒有理由 – sshashank124
您是否認爲如果'A'只是Yes或No的變體之一,您的程序將會完成? – msvalkon
您可能需要將'A = raw_input()'移動到以'print'開頭的兩行之下。目前用戶必須在看到指令之前進行確認 – Gryphius