2017-01-22 1 views
-7

RPG를 만들려고하는데 게임에서 플레이어의 캐릭터 이름을 지정할 수 있습니다. 나는 그 이름이 정의되지 않았다고 말하면서 곤경에 처하게되었다. 파이썬 2 raw_input 이해하고, 그 문제가되지 않습니다, 나는 '입력'raw_input 그것을 전혀 작동하지 않습니다, 그것을 변경하면 그냥 프로그램이 끝날 것이라고 테스트했습니다. 그리고이 문제를 해결할 수있는 사람이 있는지 알고 싶습니다. input이 평가 된 문자열을 반환 반면 파이썬 2에서플레이어 이름을 입력하는 방법은 무엇입니까?

import random 

PN = 0 
Hit = 0 
health = 50 
level = 0 
EXP = 0 
nameless_variable_1 = 0 

print("Hello, and welcome to my creation!") 
print("To begin type 1") 
print("to see credits type 2") 
print("to quit go to the X button in the corner and click it") 
print("to continue type what you want to do and hit enter on your keyboard.") 
nameless_variable_1 = input("what is your choice??????") 

if nameless_variable_1 == 2: 
    print("................. The entire game") 
    print("do you want to play the game now?") 
    print("if you do press one and then hit enter") 
    nameless_variable_1 = input(" ") 

if nameless_variable_1 == 1: 
    PN = input("what is your character Name?") 
    print("it is the year 2019 and you are trying to assasinate an important person") 
    print("if you fail at this task, you can and probably will die.") 
+0

질문이 있습니까? – MMF

+0

내 문제에 대한 도움을 요청하고 있습니다. –

+1

파이썬 2 또는 파이썬 3을 사용하고 있습니까? – ImportanceOfBeingErnest

답변

0

, raw_input 문자열을 반환합니다

다음은 내 코드 (I 개인 정보 보호 목적으로 크레딧에서 내 이름을 촬영 한)입니다. 따라서 eval('2')2 (정수로)이므로 input은 숫자에 잘 작동합니다. 그러나 이름에 대해서는 작동하지 않으므로 eval("John")은 오류를 발생시킵니다.

코드 전체에 raw_input을 사용하도록 권장합니다. 숫자의 경우 문자열과 비교할 수 있습니다. if nameless_variable_1 == "2":
이름의 경우 오류가 발생하지 않습니다.

+0

감사합니다. 그것은 내가하려고했던 것보다 잘 작동했습니다! –

관련 문제