这段代码[Python]有什么问题?
各位好, 我是一个初级程序员,我遇到了一个我无法解决的问题。当我在Python3 shell中运行我的程序时,它会显示无效语法,并在第1行中标记“:”,这意味着那里有问题。对于所有其他if/else/ifelse语句,它并没有说:是无效语法。如果我删除“:”,它将choice1()标记为红色,表示语法不正确,而缩进正好有4个空格 我真的不知道代码出了什么问题,谢谢所有帮助我的人 这是一个屏幕截图:(缩进等)这段代码[Python]有什么问题?,python,Python,各位好, 我是一个初级程序员,我遇到了一个我无法解决的问题。当我在Python3 shell中运行我的程序时,它会显示无效语法,并在第1行中标记“:”,这意味着那里有问题。对于所有其他if/else/ifelse语句,它并没有说:是无效语法。如果我删除“:”,它将choice1()标记为红色,表示语法不正确,而缩进正好有4个空格 我真的不知道代码出了什么问题,谢谢所有帮助我的人 这是一个屏幕截图:(缩进等) 关闭从用户处获取输入的行上的括号 删除elif option==“4” 删除break语
elif option==“4”
缩进你函数下的所有代码行
def gamemenu():
直到print 5 exit
你的代码就是这样的吗?你有缺少的参数,没有循环的中断和多个缩进错误。首先,你不是说“第1行”,这是一个注释。您的意思是“if option==”1:“行。这里的错误很明显,在上面的一行,你没有关闭ParenthSis。另外,你的很多代码没有正确缩进,这会导致它失败——这是Python,缩进很重要。我已经做了,但它没有出现在这里的代码中,这里缺少一个截图)呃,我太笨了,谢谢,哈哈
# For updating the version!
version = "0.1"
# For game start!
from choice1 import choice1
# insert import functions from checkpoints choices here!
def gamemenu():
print("Welcome to the RTG!")
# Starts the game
print("1. START!")
# Goes to an earlier checkpoint
print("2. CHECKPOINTS!")
# Views the "about' page
print("3. ABOUT")
# Shows my website address!
print("4. INFO ABOUT CREATOR")
# Exits the game
print("5. EXIT")
# The user input!
option = input("Make your choice, buddy! "
if option == "1":
choice1()
# elif option == "2":
# Not added yet
elif option == "3":
print("Random Text RPG, version %s" % version)
print("This is just a random game made by me for fun")
print("Please dont't take offence :(")
elif option == "4":
print("Made by Lightning Bolt."))
elif option == "5":
break
else:
print("ERROR: invalid option")
menu()
menu()
# For updating the version!
version = "0.1"
# For game start!
from choice1 import choice1
# insert import functions from checkpoints choices here!
def gamemenu():
print("Welcome to the RTG!")
# Starts the game
print("1. START!")
# Goes to an earlier checkpoint
print("2. CHECKPOINTS!")
# Views the "about' page
print("3. ABOUT")
# Shows my website address!
print("4. INFO ABOUT CREATOR")
# Exits the game
print("5. EXIT")
# The user input!
option = input("Make your choice, buddy! ") #you missed a closing parenthesis here :D
if option == "1":
choice1()
# elif option == "2":
# Not added yet
elif option == "3":
print("Random Text RPG, version %s" % version)
print("This is just a random game made by me for fun")
print("Please dont't take offence :(")
elif option == "4":
print("Made by Lightning Bolt.") # there was an extra paren here
elif option == "5":
pass #as @Padraic mentioned, there should be no break statement
else:
print("ERROR: invalid option")
menu()
menu()