Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何输入球员姓名?_Python_Python 2.7 - Fatal编程技术网

Python 如何输入球员姓名?

Python 如何输入球员姓名?,python,python-2.7,Python,Python 2.7,我正在尝试创建一个RPG,在游戏中玩家可以命名他们的角色。我遇到了一些麻烦,上面说这个名字没有定义。我理解Python2中的raw_输入,这不是问题所在,我已经测试过,如果我将'input'更改为'raw_input',它根本不起作用,它只会结束程序。我想知道是否有人能帮我解决这个问题 以下是我的代码(出于隐私目的,我已将我的姓名从信用证中删除): 在python 2中,raw_input将返回一个字符串,而input将返回一个经过计算的字符串。因此,input对数字很有效,因为eval('2'

我正在尝试创建一个RPG,在游戏中玩家可以命名他们的角色。我遇到了一些麻烦,上面说这个名字没有定义。我理解Python2中的raw_输入,这不是问题所在,我已经测试过,如果我将'input'更改为'raw_input',它根本不起作用,它只会结束程序。我想知道是否有人能帮我解决这个问题

以下是我的代码(出于隐私目的,我已将我的姓名从信用证中删除):


在python 2中,
raw_input
将返回一个字符串,而
input
将返回一个经过计算的字符串。因此,
input
对数字很有效,因为
eval('2')
给出了
2
(作为一个整数)。但是,它不适用于名称,因此
eval(“John”)
会抛出一个错误

我建议您在整个代码中使用
原始输入
。 对于数字,您可以将其与字符串进行比较
如果无名变量\u 1==“2”:


对于名称,它不会抛出错误。

有什么问题吗?我正在请求帮助解决我的问题。您使用的是python 2还是python 3?请记住,
input
将返回一个
str
,而不是
int
,因此您需要与例如
'1'
进行比较,不是
1
。所以我需要在if-nameless_变量_1==1位中设置为“1”,而不仅仅是1?谢谢!这比我想做的要好!
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.")