当我运行代码时,即使我在列表中输入一部电影,也表示它不存在并且失败。我该怎么办?

时间:2016-09-29 19:05:24

标签: python

def FilmSelection():
    list1=["The Magnificent Seven",'Wreck It Ralph','James Bond','Now you see me 2','Captain America:The Winter Soldier']
    choice=input("what film would you like to watch?")
    while choice!=str(list1[1:5]):
        print("sorry, that film is not available right now")
        choiceb=input("would you like to select a different film?")
        if choiceb=="yes"or choiceb=="Yes":
            print("that's fine")
            choice=input("what film would you like to watch?")
        else:
            print("have a nice day")
            sys.exit()
    else:
        print("lets get to times!")

1 个答案:

答案 0 :(得分:0)

当用户输入其中一个电影名称时,您的master条件将不匹配。 相反,使用这个:

while

这会发现while choice not in list1: choice in。 此外,您应该执行此操作,而不是使用list1

else