我完全迷失了为什么这不起作用.应该准确地工作吧?
UserName = input("Please enter your name: ")
print ("Hello Mr. " + UserName)
raw_input("<Press Enter to quit.>")
Run Code Online (Sandbox Code Playgroud)
我得到这个例外:
Traceback (most recent call last):
File "Test1.py", line 1, in <module>
UserName = input("Please enter your name: ")
File "<string>", line 1, in <module>
NameError: name 'k' is not defined
Run Code Online (Sandbox Code Playgroud)
它说NameError 'k',因为我'k'在测试期间写了输入.我已经读过print语句曾经没有括号但是已被弃用了吗?
我正在学习python并且有这个错误.我可以弄清楚代码中的错误是什么.
File "<string>", line 1, in <module>.
Name = ""
Desc = ""
Gender = ""
Race = ""
# Prompt user for user-defined information
Name = input('What is your Name? ')
Desc = input('Describe yourself: ')
Run Code Online (Sandbox Code Playgroud)
当我运行该程序
它输出你的名字是什么?(我输入d)
这给出了错误
Traceback (most recent call last):
File "/python/chargen.py", line 19, in <module>
Name = input('What is your Name? ')
File "<string>", line 1, in <module>
NameError: name 'd' is not defined
Run Code Online (Sandbox Code Playgroud)
这是Python 3 for Absolute Beginners的示例代码.
好的,所以我在python中编写成绩检查代码,我的代码是:
unit3Done = str(input("Have you done your Unit 3 Controlled Assessment? (Type y or n): ")).lower()
if unit3Done == "y":
pass
elif unit3Done == "n":
print "Sorry. You must have done at least one unit to calculate what you need for an A*"
else:
print "Sorry. That's not a valid answer."
Run Code Online (Sandbox Code Playgroud)
当我通过我的python编译器运行它并且我选择时"n",我得到一个错误说:
"NameError:名称'n'未定义"
当我选择"y"我再NameError有'y'是问题,但是当我做别的事情,代码运行正常.
任何帮助是极大的赞赏,
谢谢.