为什么Python中的if语句会给我一个错误?

为什么Python中的if语句会给我一个错误?,python,if-statement,statements,Python,If Statement,Statements,我正在做一个作业,我必须做一个测验,到目前为止,这是我的代码 print("Hello and welcome to Shahaad's quiz!") #Introduction name = input("What is your name? ") print("Alright", name,", these will be today's topics:") print("a) Video Games") print("b) Soccer") print("c) Geography")

我正在做一个作业,我必须做一个测验,到目前为止,这是我的代码

print("Hello and welcome to Shahaad's quiz!") #Introduction
name = input("What is your name? ")
print("Alright", name,", these will be today's topics:")
print("a) Video Games")
print("b) Soccer")
print("c) Geography") 
choice = input("Which topic would you like to begin with?")
if choice == 'video games'
    print("Lets start with Video Games!")

我试图让人们知道,如果他们选择视频游戏作为他们的第一个主题,它会打印出最后一行,但我总是在if choice=='Video games'时出错。

欢迎来到StackOverflow。你太近了

在if语句末尾需要一个冒号,如下所示:

if choice == 'video games':
    print("Lets start with Video Games!")
Python中任何打开块的东西:
for
循环、
while
循环、
if
语句、function
def
初始化等等都需要在其后面加一个冒号

但是如果用户在不同的情况下输入(
视频游戏
)会怎么样?让我们把它转换成小写来确定

if choice.lower() == 'video games':
    print("Let's start with Video Games!")

欢迎来到StackOverflow。你太近了

在if语句末尾需要一个冒号,如下所示:

if choice == 'video games':
    print("Lets start with Video Games!")
Python中任何打开块的东西:
for
循环、
while
循环、
if
语句、function
def
初始化等等都需要在其后面加一个冒号

但是如果用户在不同的情况下输入(
视频游戏
)会怎么样?让我们把它转换成小写来确定

if choice.lower() == 'video games':
    print("Let's start with Video Games!")

如上所述,您应该使用冒号。此外,您正在比较一个错误的值:用户可能键入
视频游戏
而不是
视频游戏
,或者他们也可能键入整个选项:
a)视频游戏
。因此,您应该始终检查所选单词是否在输入中,而不是整个或部分单词,如-

choice = "a) Video games"
if "Video games" in choice:
    print("You selected (a)")

如上所述,您应该使用冒号。此外,您正在比较一个错误的值:用户可能键入
视频游戏
而不是
视频游戏
,或者他们也可能键入整个选项:
a)视频游戏
。因此,您应该始终检查所选单词是否在输入中,而不是整个或部分单词,如-

choice = "a) Video games"
if "Video games" in choice:
    print("You selected (a)")

Python块应该用if语句中缺少的
表示
if-choice=='video-games':
Python块应该由if语句中缺少的
表示<代码>如果选项==‘视频游戏’: