【发布时间】:2016-04-08 06:11:03
【问题描述】:
我只用了几个月的 Python,我有点卡住了。这是一段较长的代码:
while True:
method=input('''How would you like to analyse your data?
1 = mean
2 = quartile
3 = mode
4 = range
5 = variance
6 = standard deviation
''')
if method == '1':
mean=sum(theList)/len(theList)
print('The mean of this data set is '+str(mean)+'.')
while True:
moveOn=input('Calculate another measure? Y/N ')
if moveOn == 'Y' or moveOn == 'y':
print('Redirecting...')
time.sleep(1)
break
elif moveOn == 'N' or moveOn == 'n':
print('Thank you for using the PDAP. ')
break
else:
print('Invalid response. ')
问题是,我需要 elif 选项来跳出第一个 while 循环,但也跳出第二个循环。如果有人输入“n”,我需要编程以完成并完全停止,但我似乎无法弄清楚如何做到这一点。
【问题讨论】:
-
添加 7 quit() 来打破外循环
-
这很有帮助,谢谢
标签: python loops while-loop break