2013-10-02 103 views
0

有人可以帮助我,我是编程新手,无法弄清楚为什么不能运行?Python令人困惑,需要帮助

import time 
import os 


lives = 3 

def start(): 
    global lives 

    if lives < 1: 
     print("GAME OVER") 
     quit() 

    print("You wake up in a well.") 
    print("Do you climb out or get help?") 
    well = input("Help or Climb? ") 

    if well == "H" or "h" or "help" or "Help": 
     print("You get your phone out.") 
     time.sleep(2) 
     print("There's no charge left.") 
     print(" " * 3) 
     lives = lives - 1 
     print("You have", lives, "lives left.") 
     time.sleep(3) 
     os.system("cls") 
     start() 

    elif well == "C" or "c" or "climb" or "Climb": 
     print("You start climbing up the walls of the well.") 
     time.sleep(3) 
     print("You are close, but you lose your footing and are blinded by the sunlight,") 
     footing = input("Move your foot to the left or right?") 
     if footing == "L" or "l" or "left" or "Left": 
      print("You miss the step and fall.") 
      lives = lives - 1 
      start() 




start() 
+6

当您尝试运行它时,它会告诉您什么? – mgilson

+0

'well ==“H”或“h”或“help”或“Help”是错误的。 –

+1

这样的东西:'如果well ==“H”或“h”或“help”或“Help”:'不会起作用,那么您需要'如果在[“H”,“h” ,“help”,“Help”]:'或'如果well.lower()[0] =='h':'或类似。 –

回答

0

几个提示。我建议使用raw_input而不是输入,而我通常会转换为upper,并且只是取第一个字母,例如x = raw_input('> ').upper()[0]以便以后评估更容易:

import time 
import os 


lives = 3 

def start(): 
    global lives 

    if lives < 1: 
     print("GAME OVER") 
     quit() 

    print("You wake up in a well.") 
    print("Do you climb out or get help?") 
    well = raw_input("Help or Climb? ").upper()[0] 

    if well == "H": 
     print("You get your phone out.") 
     time.sleep(2) 
     print("There's no charge left.") 
     print(" " * 3) 
     lives = lives - 1 
     print("You have", lives, "lives left.") 
     time.sleep(3) 
     os.system("cls") 
     start() 

    elif well == "C": 
     print("You start climbing up the walls of the well.") 
     time.sleep(3) 
     print("You are close, but you lose your footing and are blinded by the sunlight,") 
     footing = raw_input("Move your foot to the left or right?").upper()[0] 
     if footing == "L": 
      print("You miss the step and fall.") 
      lives = lives - 1 
      start() 




start() 
-1

在Python 3中正常工作,但在Python 2.7中不能正常工作。原因是well = input("Help or Climb? ")使用input这是Python 3代码。在Python 2.7中,你想用raw_input代替

+0

该程序包含语义错误。 –