python初步編寫用戶登錄


  python初步編寫用戶登錄

python編寫用戶登錄

    用python寫一個腳本,使得這個腳本在執行后,可以產生如下的效果:
    1、用戶的賬號為:root    密碼為:westos
    2、用戶賬號和密碼均輸入正確時,輸出" login ok !"
    3、用戶賬號輸入正確,密碼輸入錯誤,會提示密碼錯誤。
    4、用戶賬號輸入錯誤,會提示該用戶不存在。
    5、用戶賬號和密碼輸入錯誤三次后自動退出並提示輸入錯誤超過三次。

    該用戶登錄的腳本如下所示:
#!/usr/bin/env python #coding:utf-8 """ file: userlogin.py date: 2017-08-24 author:lijian desc: """ User_Name = "root" Password = "westos" print "Please input your username and password !" for i in range(1,5): if i < 4 : In_User_Name = raw_input("username : ") In_Password = raw_input("password : ") if User_Name == In_User_Name: if Password == In_Password: print "login ok" print "\n" exit(0) else: print "password is no ok !" print "\n" else: print "user is not exist ! " print "\n" else : print "count is bigger than 3 !"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
    執行該腳本后的輸出圖如下所示:

這里寫圖片描述


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM