当我运行代码时,即使我在列表中输入电影,它说它不在那里并且失败了.我该怎么办?


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!")

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

while choice not in list1:

这将发现如果choicein list1。此外,您应该这样做,而不是使用else:

while choice not in list1:
    # ...
print('Let’s go to times!')

相关内容

最新更新