program 1 : python codes for login program(登入程式python代碼),codespython
#improt time module for count down puase timeimport time#set var for loop countingcounter=1#login settingwhile counter<=3: print('please enter username: ') username=input() print('please enter password: ') password=input() #dict for username and password userinf={ 'xiaoweilai':'xiaoweilai', 'python':'123', 'education':'edu123' } #different entering cases if userinf.__contains__(username) and userinf.get(username)==password: print('welcome to python world') break else: print("username/password's error","please try again") counter=counter+1 #error entering for 3 times and forcely stop 10senconds. if counter==3: print('You try it too much times.') counter = 0 while counter <= 10: print(10 - counter) time.sleep(1) counter = counter + 1 counter=0 continue
Read me 程式說明:
設計一個需要使用者名稱和密碼的登入程式
使用者輸入登入使用者名稱和密碼,幕後處理使用者輸入的使用者名稱和密碼,即檢測已有使用者名稱和列表中有無該使用者名稱和對應的密碼是否錯誤。如果輸入錯誤,繼續嘗試第二次,若第二次錯誤,繼續嘗試第三次,如果第三次輸入錯誤則提示輸入次數太多,並暫停輸入10秒,顯示10秒倒計時。倒計時結束後,繼續嘗試。不斷迴圈,直至輸入正確的使用者名稱和密碼。程式結束。
summary 知識點總結:
time 模組應用,字典應用,while 迴圈嵌套語句,break 和 continue 語句,if else 語句。
If you like, contact me. QQ 278857042 please note: python or big data.