python第一次週末大作業
阿新 • • 發佈:2018-12-04
#############################作業#############################
1. 三次登入驗證
完成使用者登入驗證 要求: 1. 系統自動生成4位隨機數. 作為登入驗證碼. 直接用就好. 這裡不用 糾結 from random import randint num = 0 verify_code = "" while num < 4: verify_code += chr(randint(65, 90)) num += 1 print(verify_code) # 四位隨機驗證碼 2. 使用者輸入使用者名稱和密碼還有驗證碼. 3. 使用者可以有三次登入的機會. 但是驗證碼如果輸入錯誤. 不計算在 內
from random import randint count = 1 while count <= 3: num = 0 verify_code = "" while num < 4: verify_code += chr(randint(65, 90)) num += 1 # print(verify_code) # 使用者登入 username = "alex" password = "123" # 使用者輸入 uname = input("請輸入你的使用者名稱:" ) upwd = input("請輸入你的密碼:") vi_code = input(f"請輸入你的驗證碼{verify_code}:") # 判斷驗證碼 if vi_code.upper() == verify_code.upper(): print("驗證碼正確") # 判斷使用者名稱和密碼 if uname == username and upwd == password: print("登入成功") break else:print("登入失敗(還剩下%s次機會)" % (3-count)) count += 1 # ???? 000 000 - 999 999 else: print("驗證碼錯誤")