My Indentation问题从我的代码第40行开始。如果有人能告诉我如何修复它,我会非常感激
print "You wake up in a dark room, There is a box of matches in your pocket. What do you do?"
print "#1 Light a match #2 Do nothing"
door = raw_input(">")
if door == "1":
print "You light a match, In the room there is an axe and a door without a handle. What do you do?"
print "#1 Grab the axe #2 Punch the door #3 Do nothing"
axe = raw_input(">")
if axe == "1":
print "You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif axe == "2":
print"Ow, that hurt. What to do now?"
print "#1 Grab the axe #2 do nothing"
chop = raw_input(">")
if chop == "1":
print" You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif chop == "2":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
elif axe == "3":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
elif door == "2":
print"You wait in the darkness until something grabs your arm. Whate do you do?"
print"#1 Use your ninja skills to escape the clutches of whatever is grabbing you. #2 Flail your arms around"
flail = raw_input('>')
if flail == "1":
print"You escape from the things grasp. What do you do now?"
print"#Light a match. #2 Throw a punch at the whatever was attacking you"
punch = raw_input('>')
if punch == "1":
print"You light a match only to see a hideous monster in front of you. What do you do now"
print"#1 Throw the match at the monster #2 Punch the monster"
match = raw_input('>')
if match == "1":
print"You throw a match at the monster. The monster eats the match then turns dissapears. What do you do"
print"#1 Panic #2 Look around"
panic = raw_input('>')
if panic == "1":
print"You panic then have a heart attack. You die. Game over"
elif panic == "2":
print"You look around, it appears the monster is gone.In the room there is an axe and a door without a handle. What do you do?"
print "#1 Grab the axe #2 Punch the door #3 Do nothing"
axe = raw_input(">")
if axe == "1":
print "You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif axe == "2":
print"Ow, that hurt. What to do now?"
print "#1 Grab the axe #2 do nothing"
chop = raw_input(">")
if chop == "1":
print" You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif chop == "2":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
elif axe == "3":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
else:
print"Invalid Input. Game end"
else:
print"Invalid Input. Game end"
elif match == "2":
print"You punch the hideous monster in its face and it dies. You look around and you see a axe and a door without a handle. What do you do?"
print "#1 Grab the axe #2 Punch the door #3 Do nothing"
axe = raw_input(">")
if axe == "1":
print "You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif axe == "2":
print"Ow, that hurt. What to do now?"
print "#1 Grab the axe #2 do nothing"
chop = raw_input(">")
if chop == "1":
print" You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif chop == "2":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
elif axe == "3":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
else:
print"Invalid Input. Game end"
else:
print"Invalid Input. Game end"
elif punch == "2":
print"The monster eats your hand whole and you bleed to death. Game Over"
else:
print"Invalid Input. Game end"
elif flail == "2":
print"You flail your arms and then you get killed by the mmonster. Nice job. You lose. Game Over"
else:
print"Invalid input. Game end."
else:
print"Invalid Input. Game end."
答案 0 :(得分:4)
我明白了,我看到了!
elif punch == "2": # you can't `elif punch` here, because you haven't defined punch (maybe)
print"The monster eats your hand whole and you bleed to death. Game Over"
else: # else what? there's nothing here to "else!"
print"Invalid Input. Game end"
请注意,此类游戏最好使用"finite state machine"来实现,这可能会超出您的能力范围。只是想提及它,因为你目前有意大利面条代码,我不希望你认为“这是代码应该如何看”,它不应该。但是,目前的知识水平没有更好的方法:)
答案 1 :(得分:-1)
print "You wake up in a dark room, There is a box of matches in your pocket. What do you do?"
print "#1 Light a match #2 Do nothing"
door = raw_input(">")
if door == "1":
print "You light a match, In the room there is an axe and a door without a handle. What do you do?"
print "#1 Grab the axe #2 Punch the door #3 Do nothing"
axe = raw_input(">")
if axe == "1":
print "You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif axe == "2":
print"Ow, that hurt. What to do now?"
print "#1 Grab the axe #2 do nothing"
chop = raw_input(">")
if chop == "1":
print" You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif chop == "2":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
elif axe == "3":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
elif door == "2":
print"You wait in the darkness until something grabs your arm. Whate do you do?"
print"#1 Use your ninja skills to escape the clutches of whatever is grabbing you. #2 Flail your arms around"
flail = raw_input('>')
if flail == "1":
print"You escape from the things grasp. What do you do now?"
print"#Light a match. #2 Throw a punch at the whatever was attacking you"
punch = raw_input('>')
if punch == "1":
print"You light a match only to see a hideous monster in front of you. What do you do now"
print"#1 Throw the match at the monster #2 Punch the monster"
match = raw_input('>')
if match == "1":
print"You throw a match at the monster. The monster eats the match then turns dissapears. What do you do"
print"#1 Panic #2 Look around"
panic = raw_input('>')
if panic == "1":
print"You panic then have a heart attack. You die. Game over"
elif panic == "2":
print"You look around, it appears the monster is gone.In the room there is an axe and a door without a handle. What do you do?"
print "#1 Grab the axe #2 Punch the door #3 Do nothing"
axe = raw_input(">")
if axe == "1":
print "You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif axe == "2":
print"Ow, that hurt. What to do now?"
print "#1 Grab the axe #2 do nothing"
chop = raw_input(">")
if chop == "1":
print" You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif chop == "2":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
elif axe == "3":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
else:
print"Invalid Input. Game end"
else:
print"Invalid Input. Game end"
elif match == "2":
print"You punch the hideous monster in its face and it dies. You look around and you see a axe and a door without a handle. What do you do?"
print "#1 Grab the axe #2 Punch the door #3 Do nothing"
axe = raw_input(">")
if axe == "1":
print "You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif axe == "2":
print"Ow, that hurt. What to do now?"
print "#1 Grab the axe #2 do nothing"
chop = raw_input(">")
if chop == "1":
print" You grab the axe, What do you do?"
print "#1 Knock down the door #2 Do nothing"
end = raw_input(">")
if end == "1":
print "You are free! You Win!"
elif end == "2":
print"You wait and then the axe slips out of your hand, decapacitating you. You die"
else:
print "Ivalid input. Game End"
elif chop == "2":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
elif axe == "3":
print "You go insane from waiting. Game Over"
else:
print "Ivalid input. Game End"
else:
print"Invalid Input. Game end"
else:
print"Invalid Input. Game end"
elif punch == "2":
print"The monster eats your hand whole and you bleed to death. Game Over"
else:
print"Invalid Input. Game end"
elif flail == "2":
print"You flail your arms and then you get killed by the mmonster. Nice job. You lose. Game Over"
else:
print"Invalid input. Game end."
else:
print"Invalid Input. Game end."
需要新版本的python
的括号