2014-02-23 77 views
0

我的缩进问题始于第40行在我的代码中。如果有人能告诉我如何修复它,我会非常感谢基于Python文本的游戏缩进

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."  
+2

请重新格式化代码格式您的文章,并张贴确切的错误消息你收到。在此之前,给你一个解决方案或多或少是不可能的。 –

+0

@JakobBowyer“你在做什么?你做得很糟糕,你应该做得更好。”这就是你刚才告诉他的。这是怎样的建设性?如果你有一个特定的方法,他可以更好地实现这一点,你应该写它作为一个答案(就像我建议一个有限状态机时那样) –

+0

指示哪一行是第40行可能是一个好开始... – twalberg

回答

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",这可能是一个有点超出你的能力在那一刻实现。只是想提及它,因为你现在有意大利面条代码,我不希望你认为“这是代码应该看的样子”,它不应该。有,但是,没有更好的办法,以你目前的知识水平:)做

+0

你是对,但你搞砸了格式化了一下。打印正确缩进这是其他的不好。 – DeadChex

+1

@DeadChex其实我错过了一切的缩进。它现在已经修复:) –

+0

好,只是想确保缩进不会咬你 – DeadChex

-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." 

需求括号蟒蛇的新版本

+0

如果你想让别人读取它,你最好格式化你的代码。 –