【发布时间】:2017-06-07 05:53:27
【问题描述】:
我正在尝试创建一个角色扮演游戏,在游戏中玩家可以命名他们的角色。我遇到了一些麻烦,它说名称未定义。我了解python 2中的raw_input,这不是问题,我已经测试过,如果我将'input'更改为'raw_input'它根本不起作用,它只会结束程序。我想知道是否有人可以帮助我解决这个问题。
以下是我的代码(出于隐私目的,我已将我的名字从积分中删除):
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.")
【问题讨论】:
-
有什么问题吗??
-
我正在就我的问题寻求帮助。
-
你用的是python 2还是python 3?
-
请记住
input将返回str,而不是int,因此您需要与例如'1',不是1。 -
所以我需要在 if nameless_variable_1 == 1 位中将其设为“1”而不仅仅是 1?
标签: python python-2.7