我在用python编程时收到idle发出的“预期缩进错误”。我在试着编一个文字故事。你知道吗
这是我的密码:
import time
choice1 = input("you walk into a haunted house, do you take door #1 or door #2?(1/2)")
if choice1 == "1":
door1 = input("You see a staircase... go up or down? (up/down)")
if door1 == ("up"):
if door1 == ("down"):
print ("AHHHHHHHH.....")
time.sleep(1)
print ("AHHHHHHHH.....")
time.sleep(1)print (".........")
time.sleep(1)
print("THUNK. you slipped off the ladder and died because you fell for so long")
if choice1 == "2":
print ("ahhhhhhhhhhhhhh")
time.sleep(1)
print("oooff, you fell into a dark room, try to find your flashlight or wander around? (flashlight/wander)")
每个块下面都应该有代码
可以更改为
您必须小心缩进,python在缩进中很严重,您必须在if语句之后添加一些语句,尝试使用
pass
。此外,它将每个句子分隔成一行。你知道吗发生错误的原因是您的块中没有语句。你知道吗
Python语法需要在if、except、def、class等后面加上代码块
这里,
if door1 == ("up"):
是空的。你知道吗如果不需要在代码块中执行任何操作,则在这样的块中包含
pass
以不生成IndentationError
。你知道吗pass语句不执行任何操作。当在语法上需要一个语句,但程序不需要任何操作时,可以使用它。你知道吗
在代码中,使用
相关问题 更多 >
编程相关推荐