Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我不能使用if语句,因为语法无效_Python_If Statement - Fatal编程技术网

Python 我不能使用if语句,因为语法无效

Python 我不能使用if语句,因为语法无效,python,if-statement,Python,If Statement,它不允许我运行此代码。我不明白为什么。 代码如下: 我看过你的代码,有很多错误。首先,在使用if语句时,需要缩进并使用冒号。这就是为什么会出现无效的语法错误 但是,请尝试下面的代码。它可以让用户输入他们的决定,如果他们选择我的,就打印好 die = input ("Whose team are you on? Mine or yours?") if die == "Mine": print ("good") 希望这有帮助 首先,确保您的代码正确且定期缩进,因为这是Python决定if语

它不允许我运行此代码。我不明白为什么。 代码如下:


我看过你的代码,有很多错误。首先,在使用if语句时,需要缩进并使用冒号。这就是为什么会出现无效的语法错误

但是,请尝试下面的代码。它可以让用户输入他们的决定,如果他们选择我的,就打印好

die = input ("Whose team are you on? Mine or yours?")
if die == "Mine":
    print ("good")

希望这有帮助

首先,确保您的代码正确且定期缩进,因为这是Python决定if语句中包含哪些内容和不包含哪些内容的方式

其次,必须在条件后添加冒号,否则将出现语法错误

您的代码应该如下所示:

print("Whose team are you on?")
die = int(input("1 - Mine     2 - Yours"))
if die == 1:
    print("good")
else:            #This is optional but always nice to include
    print("bad")

很好的解决方案!现在你应该编辑答案了!对不起,我当时是个十足的傻瓜,我现在明白了。无论如何,感谢所有愿意帮忙的人。
print("Whose team are you on?")
die = int(input("1 - Mine     2 - Yours"))
if die == 1:
    print("good")
else:            #This is optional but always nice to include
    print("bad")