這個問題在這里已經有了答案: 要求用戶輸入,直到他們給出有效的回應 (22 個答案) 18 小時前關閉。
我正在為我的大學做一個python專案,在專案中我有一個帶有用戶名和密碼的登錄資訊,但我希望如果用戶錯誤,代碼再次重復,如果用戶正確,代碼通過并且相同的情況如果密碼錯誤,則密碼從零開始,如果密碼正確,則代碼繼續休息,但我不知道該怎么做,所以請幫助,非常感謝您的幫助。
User=input("Type the User: ")
if User=="Admin":
print("User correct")
Password=input("Type the password: ")
else:
print("User incorrect")
#In here if the user are incorrect, I need the firts starover
if Password=="admin":
print("Nice, continue")
else:
print("Wrong password")
#In here if the password are incorrect, I need the other starover.
uj5u.com熱心網友回復:
您可以使用 while 來解決此問題:
回圈直到用戶名/密碼正確。
這是我的解決方案:
User=""
Password=""
while(User != "Admin"):
User = input("Type the User: ")
if User=="Admin":
print("User correct")
else:
print("User incorrect")
#Do same thing with password
while(Password != "admin"):
Password=input("type password")
if Password=="admin":
print("Nice, continue")
else:
print("Wrong password")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/432194.html
標籤:Python python-3.x
下一篇:你如何使用dx?
