2010-04-11 4 views
3

저는 Mac에서 Python을 사용하는 초급 프로그래머입니다.Python에서 코드를 실행하는 알 수없는 이유

주인공의 이름에 대한 플레이어의 입력을받는 게임의 일부로 함수를 만들었습니다.

코드는 다음과 같습니다 제가 테스트 때

import time 

def newGameStep2(): 
     print ' ****************************************** ' 
     print '\nStep2\t\t\t\tCharacter Name' 
     print '\nChoose a name for your character. This cannot\n be changed during the game. Note that there\n are limitations upon the name.' 
     print '\nLimitations:\n\tYou cannot use:\n\tCommander\n\tLieutenant\n\tMajor\n\t\tas these are reserved.\n All unusual capitalisations will be removed.\n There is a two-word-limit on names.' 
     newStep2Choice = raw_input('>>>') 
     newStep2Choice = newStep2Choice.lower() 
     if 'commander' in newStep2Choice or 'lieutenant' in newStep2Choice or 'major' in newStep2Choice: 
      print 'You cannot use the terms \'commander\', \'lieutenant\' or \'major\' in the name. They are reserved.\n' 
      print 
      time.sleep(2) 
      newGameStep2() 
     else: 
      newStep2Choice = newStep2Choice.split(' ') 
      newStep2Choice = [newStep2Choice[0].capitalize(), newStep2Choice[1].capitalize()] 
      newStep2Choice = ' ' .join(newStep2Choice) 
     return newStep2Choice 

myVar = newGameStep2() 
print myVar 

, 나는 '주요 A'를 입력하고, 입력에 다른 이름을 나에게 물었을 때, 나는 'A B'를 입력. 그러나 함수의 출력을 반환하면 'major a'가 반환됩니다. 디버거를 사용하여이 과정을 밟았지만 아직 문제가 발생한 부분을 찾을 수없는 것 같습니다. 어떤 도움

감사합니다, 재스퍼

newGameStep2()에 대한 귀하의 재귀 호출, 그래서 두 번째 호출이 완료가, 제어 흐름이 경우/다른 블록 후 첫 번째 호출에 계속하고, return newStep2Choice 반환을 반환하지 않습니다

답변

8

첫 번째 읽기 값. 재귀 호출을 다음과 같이 변경해야합니다.

return newGameStep2() 
관련 문제