0
我一直在使用python在eclipse上,並且當我提出一個問題時,我遇到了麻煩,並且響應包含字母(數字答案工作)。例如,如果我問爲什麼不能使用此代碼? (新編碼)
x=input("what is your name")
print(x)
這將給我一個類似於底部的錯誤信息。下面是我正在嘗試與上面的代碼相同的錯誤。
x=input("enter a number")
y=input("enter a second number")
z=input("add, divide, or multiply?")
if(z == "add"):
print(x+y)
if(z == "divide"):
print(x/y)
if(z == "multiply"):
print(x*y)
else:
print("error")
下面
是我所得到的,一旦我得到的地方,我不得不選擇「添加,除以或乘」部分
Traceback (most recent call last):
File "/Users/jacobmaldonado/Desktop/untitled folder/abc/src/def.py", line 10, in <module>
z=input("add, divide, or multiply?")
File "/Users/jacobmaldonado/Downloads/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev_4.2.0.201507041133/pysrc/pydev_sitecustomize/sitecustomize.py", line 141, in input
return eval(raw_input(prompt))
File "<string>", line 1, in <module>
NameError: name 'add' is not defined
你好,歡迎來到StackOverflow。請花一些時間閱讀幫助頁面,尤其是名爲[「我可以詢問什麼主題?」(http://stackoverflow.com/help/on-topic)和[「我應該問什麼類型的問題避免問?「](http://stackoverflow.com/help/dont-ask)。更重要的是,請閱讀[Stack Overflow問題清單](http://meta.stackexchange.com/q/156810/204922)。您可能還想了解[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 –
https://en.wikibooks.org/wiki/Python_Programming/Input_and_Output#input.28.29:'input()使用raw_input來讀取一串數據,然後嘗試評估它,就好像它是一個Python程序一樣使用 –
'raw_input'而不是'input' – NightShadeQueen