如何在1个变量中接受多个答案

时间:2018-10-31 23:02:25

标签: python python-3.x

im试图使用户为Fav_show输入不同的字符串,从而可以触发正确的显示。我尝试过Fav_show = ("game of thrones", "GOT")Fav_show = ("game of thrones" or "GOT"),但是如果我进入权力/ GOT游戏,我的脚本会生成guess != Fav_show,我将如何为多个答案制作guess = Fav_show

Fav_show = ("game of thrones")
guess = ""
guess_count = 0
guess_limit = 0
guess_a_show = False

if raw_input == "whats your favourite tv show":
    guess_a_show = input("you have to take a guess, okay? ")
    if guess_a_show == "okay":
        print("take a guess, you have 5 chances ")
        while guess != Fav_show and guess_count < 1:

对不起,我是python的新手,我已经尝试环顾了大约30-45分钟,但也许我在找错地方了

2 个答案:

答案 0 :(得分:0)

您可以创建一个包含用户可能答案的列表:

got_list = ['got','权力游戏','GOT']

然后:

while guess not in got_list and guess_cout < 1

答案 1 :(得分:0)

除了手动遍历整个列表并与for x in list...进行比较,您还可以使用in运算符:

if x in list return True甚至更好的是直接返回in比较return x in list,请记住,对于字符串比较,字母大写确实起作用了,您应该使用{{1 }}或'string'.upper()'