如有錯誤歡迎大家指出,新手初來乍到。程序沒那么復雜,是最簡單的。
一、需求
編寫登錄文件 .py
1. 輸入用戶名密碼
2. 正確,輸出歡迎登錄
3. 當輸入用戶名和密碼小於 3 次,輸入用戶名或者密碼錯誤,提示用戶名或者密碼錯誤。再次輸入用戶名和密碼,剩余輸入次
數。
3. 當輸錯三次后退出
二、流程圖
三、代碼
for
#!/usr/bin/env python #_*_conding:utf-8_*_ user = "zhangjinglei" password = "lei100103" count = 0; for i in range(3): username = input("username:") password = input("password:") if username == user and password == password: print("Welcome Login") count = 3 break else: print("Wrong username or password") count += 1 print("you can try", 2 - i, "times")
while
#!/usr/bin/env python #_*_conding:utf-8_*_ user = "zhangjinglei" password = "lei100103" count = 0; while count < 3: username = input("username:") password = input("password:") if username == user and password == password: print("Welcome Login") count = 3 else: print("Wrong username or password") count += 1 print("you can try", 3 - count, "times")
四、驗證結果
1.for 驗證結果
2.whlie驗證結果