2014-10-02 3 views
-1

파이썬 2.7

윈도우왜이 루핑되지 않습니까?

한번 '플레이'를 입력 7 :

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

그것은 어떻게해야 무엇 않습니다. 'play'을 두 번 잘못 입력하면 루핑 대신 두 번 종료됩니다. 구글에를 검색하지만 아무것도 찾을 수 없습니다 :/

코드 : 코드에서

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() 

답변

2

봐 : 당신이 잘못 입력 "재생"것처럼 어떻게됩니까

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() 

는 "게임의" 처음으로? 음, startg()으로갑니다. 조건부 if(game=="Play")이 있지만 올바른 입력 이외의 내용을 처리하려면이 아닌 문이 없습니다. 따라서 두 번째로 "재생"을 입력하면 프로그램에서 고려하지 않은 조건이됩니다. 따라서 어떤 함수도 호출되지 않고 프로그램은 끝까지 진행됩니다.

덧붙여 else 문을 도입하여 "Play"의 철자가 틀린 모든 경우를 처리해야합니다. 올바르게 대문자로 쓰지 않아도 처리 할 수있는 유일한 오류는 아닙니다.

+0

나는 그것이 단순 할 것이라고 알고 있었다. 고마워! 기음: –

관련 문제