为什么这不是循环? Python 2.7

为什么这不是循环? Python 2.7,python,python-2.7,Python,Python 2.7,视窗7 当我键入一次“播放”时: 它做它应该做的事。当我输入“play”两次错误时,它不是循环而是退出。在谷歌上搜索,但什么也找不到:/ 代码: 看看你的代码: def startg(): game = raw_input("Type 'Play' to start. ") if(game == "Play"): print("Loading. . . ") playg() if(game == "play"): print("Make sure you type 'Play', CaPS

视窗7

当我键入一次“播放”时:

它做它应该做的事。当我输入“play”两次错误时,它不是循环而是退出。在谷歌上搜索,但什么也找不到:/

代码:

看看你的代码:

def startg():
game = raw_input("Type 'Play' to start. ")
if(game == "Play"):
 print("Loading. . . ")
 playg()

if(game == "play"):
print("Make sure you type 'Play', CaPS MaTteR! ")
startg()
elif(game == "Play"):
playg()
如果第一次输入Play时出错,会发生什么情况?好吧,它去了startg。有条件的ifgame==Play,但是除了正确的输入之外,没有其他语句来处理任何事情。因此,如果第二次键入play,则会导致程序无法解释的情况。因此,不调用任何函数,程序将一直进行到最后


顺便说一下,您应该引入一个else语句来处理以其他方式拼写错误的所有情况。不正确地大写并不是您应该准备处理的唯一潜在错误

我就知道会很简单,谢谢!c:
name = raw_input("What is your name? ")
gender = raw_input("What are you, a Boy or a Girl? ")
print(" ")

if(gender == "Boy"):
their = "his "
else:
their = "her "

game = raw_input("Type 'Play' to start. ")

def endg():
print("Hope you had fun! ~Red")

def startg():
game = raw_input("Type 'Play' to start. ")
if(game == "Play"):
 print("Loading. . . ")
 playg()

listq1 = ["A. Quit your job." , "B. Pretend you never saw the stack of papers." , "C.             Kill yourself because you don't feel like playing this game. "]

def playg():
answer = raw_input("You are a programmer, " + name  + ", who hates " + their + "job     very much." +
      " You walk into work to see a huge stack of papers on your desk... What do you     do? \n" + "\n".join(listq1))
if(answer == "A"):
    print("\nYou look around the room and see the flock of miserable people...Your     Co-Workers.  Is working here really worth the stress? ")
elif(answer == "B"):
    print("\nYou pull the over-sized recycle bin out from under your desk.  Just as you start to slide the papers to their impending doom, a fellow co-worker stops to ask what you are doing. ")
elif(answer == "C"):
    endg()

if(game == "play"):
print("Make sure you type 'Play', CaPS MaTteR! ")
startg()
elif(game == "Play"):
playg()
def startg():
game = raw_input("Type 'Play' to start. ")
if(game == "Play"):
 print("Loading. . . ")
 playg()

if(game == "play"):
print("Make sure you type 'Play', CaPS MaTteR! ")
startg()
elif(game == "Play"):
playg()