如果输入=列表[N]:我将如何设置呢?

问题描述 投票:3回答:1

我总是就行了错误的输入,但我不知道如何解决它。对不起,如果它的格式不正确。

这是关于Python 2.6

videoGames = ["Fortnite", "Minecraft", "Roblox", "2048", "Mario Cart"]
favGame = raw_input("What is your favorite video game?")
if favGame == videoGames[1]
    print("Hi.")
print("Really?! We both enjoy playing") #add the input that matches with the list

如果用户输入匹配列表中的项目之一,那么它会打印出“真的?!我们都喜欢玩(游戏)

python list if-statement printing
1个回答
3
投票

你缺少在这一行冒号:

if favGame == videoGames[1]

它应该是

if favGame == videoGames[1]:

要打印的游戏:

if favGame in videoGames:
    print("Really?! We both enjoy playing", favGame)
© www.soinside.com 2019 - 2024. All rights reserved.