![](/img/trans.png)
[英]I couldn't get results when I write compiled code in Visual Studio Code, I run python deploy.py and it gives me error. what I have to edit in my code
[英]How can I write this python input code? What I have gives me an error message
我在 python 文件first.py
有以下代碼
person=input("enter your name:")
print("helo ",person)
我希望它以我輸入的名字返回“helo person”,但是當輸入並按回車鍵時,我看到的是一條錯誤消息,表明該名稱未定義。
該代碼在 thonny IDE 中運行良好,但在 IDLE shell 中運行良好,任何知道為什么幫助我的人都可以嗎?
我是編程的新手。
如果您收到這樣的錯誤代碼,並且它在您的其他 IDE 中按預期工作,則 IDLE 似乎使用的是 python 2.x,輸入/打印語法對它的影響略有不同。
person = raw_input("enter your name: ")
print("hello {}".format(person))
person = input("enter your name: ")
print("hello ",person)
您正在使用 python 3 樣式的input
函數,但您使用的是 python 2.7。 嘗試:
person = raw_input("enter your name:")
print "Halo "+ person
有多種方法可以打印您想要的內容。 嘗試:
print('helo %s' %person)
或者
print('helo {}'.format(person))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.