2015-10-11 50 views
-3
File "<stdin>", line 63 
    elif answerthree == "go to gas station": 
    ^
SyntaxError: invalid syntax 

未知錯誤。請解決此錯誤

我將在while true:位,我做的時候,我得到這個:

print "hello, and welcome to your world!" 
print "are you ready?" 
while True: 
     answerone = raw_input("yes or no?").lower() 
     if answerone == "yes" or answerone == "y": 
      break 
      print "well fantastic! your at a crossroads you can go left or right..." 
     while True:  
      answertwo = raw_input("left or right?").lower() 
      if answertwo == "left" or answertwo == "l": 
       break 
       print "you got hit by a car your dead" 
       print "gameover" 
      elif answertwo == "right" or answertwo == "r": 
       break 
       print "you see a gas station" 
       print "but you also she something shiny in the sand" 
      while True:  
       answerthree = raw_input("grab the shiny object or go to the gas station?").lower() 
       if answerthree == "grab shiny object": 
        break 
        print "you found a GUN!" 
        print" but it only has" 
        from random import randint 
        bullets = (randint(2,9)) 
        print bullets 
       print "bullets" 
       while True:  
        answerfive = raw_input("do you continue to the gas station or go to a nearby building to sleep? type either gas station or sleep") 
        if answerfive == "sleep": 
         break 
         print " you went to a nearby building to sleep." 
        elif answerfive == "gas station": 
         break 
         print "on your way to the gas station you encounter enemys inside the building" 
        print "there are" 
        enemys = (randint(2,9)) 
        print enemys 
        print "of them" 
       while True:  
        answersix = raw_input("do you try to shoot them with your gun or flee to a nearby building? type either shoot or flee") 
        if answersix == "shoot": 
         break 
         print " you go to shoot them" 
         if enemys>7: 
          print "when you went to attack you were overpowered by their numbers and died" 
          print "game over" 
         elif enemys<7: 
          print "you went to attack them and emerged victorious!" 
          bullets = bullets-enemys 
          if bullets<0: 
           bullets = 0 
          print "you now only have" 
          print bullets 
          print "left" 
         else: 
          print "error" 
        elif answersix == "flee": 
         break 
         print " you flee to a nearby building where you sleep for the night" 
        else: 
         print "you diddnt type anything!" 
       elif answerthree == "go to gas station": 
        break 
        print "on your way to the gas station you encounter enemys inside the building" 
        print "there are" 
        enemys = (randint(2,9)) 
        print enemys 
        print "of them" 
       while True  
        answerfour = raw_input("do you try to fight them with your fists or flee to a nearby building?") 
        if answerfour == "fight them": 
         break 
         print " you go to attack them" 
         if enemys>3: 
          print "when you went to attack you were overpowered by their numbers and died" 
          print "game over" 
         elif enemys<3: 
          print "you went to attack them and emerged victorious!" 
         else: 
          print "error" 
        elif answerfour == "flee": 
         break 
         print " you flee to a nearby building where you sleep for the night" 
        else: 
         print "you diddnt type anything!" 
       else: 
        print "you diddnt type anything!" 
      else: 
       print " you diddnt type anything!" 
     elif answerone == "no" or answerone == "n": 
      break 
      print "well this was a fun game wasnt it?" 
     else: 
      print "you diddnt type anything!" 
+0

是否已經閱讀了[旅遊] – Kroltan

+0

'while True'缺少冒號(:) – PeterMmm

+2

您的代碼*相當*雜亂。你可以考慮把它分成不同的類和功能。 – sobolevn

回答

2

elif answerthree == "go to gas station":不匹配任何if

+0

它的縮進匹配了一段時間,但是......有一段時間後沒有elif :) – Roberto

+0

你能告訴我嗎?對不起,我只是昨天學習了python的基礎知識(只有5個小時) –

+0

我編輯了答案。但是像其他人告訴你的那樣 - 'elif'應該匹配另一個'if'子句的縮進。否則,這是一個語法錯誤。 – zanderle