program 1 : python codes for login program(登入程式python代碼),codespython

來源:互聯網
上載者:User

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.   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.