参见英文答案 >
error in python d not defined. 3个
我一直在学习如何使用“Python绝对初学者指南”这本书编写Python程序.我遇到的问题是,当使用eclipse-pydev时,它不允许我使用if语句.这是我写的代码……
name = input("What is your name? ")
print(name)
print("Hello" name )
结果是
What is your name? caleb
Traceback (most recent call last):
File "/Users/calebmatthias/Document/workspace/de.vogella.python.first/simpprogram.py", line 6, in
name = input("What is your name? ")
File "/Users/calebmatthias/Desktop/eclipse 2/plugins/org.python.pydev_2.2.3.2011100616/PySrc/pydev_sitecustomize/sitecustomize.py", line 210, in input
return eval(raw_input(prompt))
File "", line 1, in
NameError: name 'caleb' is not defined
当我做我的if语句时,我把它
name = input("What is your name? ")
if name == ("Caleb"):
print(" Hello Bud!")
结果是
What is your name? Caleb
Traceback (most recent call last):
File "/Users/calebmatthias/Document/workspace/de.vogella.python.first/simpprogram.py", line 6, in
name = input("What is your name? ")
File "/Users/calebmatthias/Desktop/eclipse 2/plugins/org.python.pydev_2.2.3.2011100616/PySrc/pydev_sitecustomize/sitecustomize.py", line 210, in input
return eval(raw_input(prompt))
File "", line 1, in
NameError: name 'Caleb' is not defined