Jak*_*ke 3 python while-loop python-2.7
所以这就是我正在努力解决的问题.我希望Yes和No两者都相同,并且结束循环(我还没有开始),但是当输入的内容不是Yes或No时它会再次循环问题,直到是或否输入.我无法弄清楚如何做这个部分,我还在学习,而循环对我来说是个新的基础.
我正在使用2.7
d1 = raw_input('Please answer with Yes or No.\n')
if d1 == 'Yes':
print('Good, let\'s begin.')
elif d1 == 'No':
print('Good, let\'s begin.')
if d1 == 'yes':
print('Good, let\'s begin.')
elif d1 == 'no':
print('Good, let\'s begin.')
else:
ps('Mmmmm...')
Run Code Online (Sandbox Code Playgroud)
试试这个:
while True:
d1 = input('Please answer with Yes or No.\n')
if d1.lower() in ('yes', 'no'):
print('Good, let\'s begin.')
break
else:
print('MMMMmm')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
893 次 |
| 最近记录: |