Python學習週末練習1-使用者登入
阿新 • • 發佈:2018-11-17
使用者登入驗證
要求:
1.使用者登入輸入賬號、密碼、4位隨機大寫字母驗證碼
2.驗證碼錯誤重新輸入
3.有三次機會輸入賬號密碼
count = 1 while count <= 3 : from random import randint num = 0 verify_code = "" # 建立一個空字串放驗證碼 while num < 4: verify_code += chr(randint(65, 90)) num += 1 usernum = input("請輸入賬號") code = input("請輸入密碼") verify_code_1 = input("請輸入驗證碼(%s)" %verify_code) if usernum == "左志博" and code == "123" : if verify_code_1 == verify_code: print("輸入正確") break else : print("驗證碼錯誤,請重新輸入") continue else : print("輸入錯誤,你還有%s次機會"% (3-count)) count += 1