# 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()
大家好,
我是初学程序员,遇到了一个我无法解决的问题。当我在Python 3 shell中运行我的程序时,它表示无效语法并在第1行中标记“:”为红色,这意味着存在错误。对于所有其他if / else / ifelse语句,它不会说:语法无效。如果我删除了“:”,它会将choice1()标记为红色,表示语法不正确,而它的缩进只有4个空格。
我真的不知道代码有什么问题,感谢任何帮助我的人!
这是截图:http://imgur.com/wuWMa0L(缩进等)
答案 0 :(得分:1)
elif option == "4"
代码:
# 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()