它不会让我运行这段代码。我不明白为什么。这是代码: https://repl.it/G7Kx
print ("Whose team are you on?")
die = int(raw_input("1.) Mine (2.) Yours"))
if die == "1"
print ("good")
我看了一下你的代码,有很多错误。首先,在使用 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")