2017-01-22 5 views
-7

RPGを作成しようとしていますが、プレイヤーはそのキャラクターに名前を付けることができます。私は名前が未定義であると言っているいくつかの問題に遭遇した。私はPython 2でraw_inputを理解していますが、それは問題ではありません。私は '入力'を 'raw_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

あなたはpython 2またはpython 3を使用していますか? – ImportanceOfBeingErnest

答えて

0

inputが評価された文字列を返しますながらraw_inputは、文字列を返します。したがって、eval('2')2(整数として)を返すので、inputは数値には問題ありません。しかしそれは名前のために働かないので、eval("John")はエラーを投げます。

コード全体でraw_inputを使用することをお勧めします。 数字の場合は、文字列と比較すると if nameless_variable_1 == "2":
となりますが、名前はエラーになりません。

+0

ありがとう!それは私がやろうとしていたよりもうまくいった! –

関連する問題