[英]Coding python on android
首先,對不起。 我對編程和在Android設備上編程都是陌生的,但是由於某種原因,當我去編譯此代碼並使用Python For Android運行它時。 它不斷返回此錯誤:
文件“ /storage/emulated/programming/pass.py”,第4行,在
用戶名=輸入(“用戶名:”)文件“”,NameError中的第1行:未定義名稱“用戶”
security = 0
username = ""
while not username:
username = input("username: ")
password = ""
while not password:
password = input("password: ")
if username == "user" and password == "pass":
security = 5
print (" Hello, security level is:" , security)
else:
print("invalid login")
現在,當我在PC上運行相同的代碼時,沒有出現此錯誤。 這里有人熟悉使用適用於Android和Droidedit的Python編寫Python代碼嗎? 我已經安裝了所有可用的模塊。
我猜測p4a不是py3.0 +,因此您需要不input
raw_input
python2中的raw_input
與python3 +中的input
相同
在python2中使用input
與在python 3中執行eval(input("Username:"))
>>> x = raw_input("Enter Equation:")
Enter Equation: 5 + 3
>>> print repr(x)
'5 + 3'
>>> y = input("Enter Equation:") #this is the same as eval(input(msg)) in py3+
Enter Equation: 5 + 3
>>> print repr(y)
`8`
有關您的錯誤的一些其他信息。 在python2輸入中,嘗試將用戶輸入評估為python代碼。 您正在輸入“用戶”作為用戶名。 然后,python嘗試將其解釋為將其解釋為變量的代碼。 例如,如果您輸入543作為用戶名,它將可以正常工作。 另外,如果您輸入“用戶”(包括引號),則將可以正常工作,因為兩者都將評估為python值(引號使它成為字符串而不是變量,並且python知道int是什么)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.