0
我想弄清楚为什么任何以'y'开头的输入都会让这个游戏继续运行....看着它只出现'y'或'yes'的代码应该保持它运行,但是我可以输入'yensdg','yyyy'等,它仍然会循环。骰子模拟器输入 - Python
任何想法?由于
from random import randint
repeat = True
while repeat:
print('You rolled', randint(1,6))
print('Do you want to roll again?')
repeat = ('y' or 'yes') in input().lower()
@vaultah如果我有一美元每次有人得到了与抓在python中失败的伪自然语言语法... –
input()。lower()中的'y',如果输入字符串中的任何位置存在'y',则此语句将返回true。就像输入是'thisisarandominputwithy'一样,它会返回true,因为它最后有'y'。 –
将最后一行更改为:repeat = input()。lower()in ['y','yes'] –