如题,我在做一个猜年龄的程序时,遇到一个循环卡住了,不懂为什么达不到我想要的要求
我想要的是在输入除了YyNn这四个以外的字母时需要再重新输入直到正确为止
python新手,求指教
z = 19
i=0
print('这是一个猜年龄的游戏!')
print('你只有三次机会!')
while i<=3:
age = int(input('请输入:'))
if z == age:
print('你猜对了!')
break
pass
elif age>19:
print('猜大了')
else:
print('猜小了')
pass
i+=1
if i==3:
choose = input('你还想继续玩吗:')
while choose !='Y' or choose !='y' or choose !='N' or choose != 'n':
choose = input('请输入正确的选择...:')
if choose =='Y' or choose =='y':
i=0
elif choose =='N' or choose == 'n':
break
pass
pass
while choose !='Y' or choose !='y' or choose !='N' or choose != 'n': 这错了
choose 不等于Y or 不等于y 不论choose输入什么,都永远正确,就成死循环了
应该这样表达: while len(choose)!=1 or choose not in 'YyNn':
z = 19
i = 0
print('这是一个猜年龄的游戏!')
print('你只有三次机会!')
while i<=3:
age = int(input('请输入:'))
if z == age:
print('你猜对了!')
break
elif age>19:
print('猜大了')
else:
print('猜小了')
i+=1
if i==3:
choose = input('你还想继续玩吗:')
while len(choose)!=1 or choose not in 'YyNn':
choose = input('请输入正确的选择...:')
if choose =='Y' or choose =='y':
i=0
elif choose =='N' or choose == 'n':
break
while choose !='Y' or choose !='y' or choose !='N' or choose != 'n':
这个循环条件是不是应该为 and 不是 or?