所以我正在为我的新工作学习python,从java背景开始,我遇到了以下错误。
我尝试在终端上运行这个模块(使用 mac),然后通过 IDLE。都是徒劳的。
userName = input("What is your name?: ")
lengthName = str(len(usernName))
yourName = "\nYour name is " + userName + " and is " + legnthName + " letters long."
print(yourName)
input("\nPress enter to exit")
当这在终端中执行并且我输入第一个输入时:“John”我得到这个结果:
File "[...]", line 1, in <module>
userName = input("What is your name?: ")
File "<string>", line 1, in <module>
NameError: name 'John' is not defined
同样,当通过 IDLE 执行时:
Traceback (most recent call last):
File "/Users/zachmartin/Desktop/python fails/lol.py", line 2, in <module>
lengthName = str(len(usernName))
NameError: name 'usernName' is not defined
这里发生了什么?