python用戶管理系統(tǒng)
本文實(shí)例為大家分享了Python用戶管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
用戶管理系統(tǒng)
1.注冊新用戶
如果注冊用戶已經(jīng)存在,則報錯
需要填寫信息: name, passwd, gender, email,age
2.用戶登錄 要求同之前寫的用戶登錄系統(tǒng)
3.注銷用戶 用戶注銷時,需要輸入用戶名和正確的用戶密碼
4.顯示用戶信息 顯示系統(tǒng)中存在所有已經(jīng)注冊用戶的信息
5.退出系統(tǒng)
代碼如下
#!/usr/bin/env python #coding:utf-8 info = """ ************************************************************ 用戶登錄管理系統(tǒng) ************************************************************ 1. 注冊新用戶 2. 用戶登錄 3. 用戶注銷 4. 用戶信息顯示 5. 退出系統(tǒng) """ userinfo = { 'root': { 'name': 'root', 'password': 'redhat', 'gender': 1, 'email': '', 'age': 12 }, } gender_choice = [0, 1, 2] def CreateUser(): print "注冊用戶界面".center(50, '*') name = raw_input("*注冊用戶名:") if name in userinfo: print "用戶已存在,請更換注冊名" else: password = raw_input("*用戶密碼:") while True: gender = input("*性別(0-男 1-女 2-其他):") if gender in gender_choice: break else: print "請輸入正確的選擇" email = raw_input("用戶郵箱:") if not email: email = None age = raw_input("年齡:") if not age: age = None else: age = int(age) userinfo[name] = { 'name': name, 'password': password, 'gender': gender, 'email': email, 'age': age, } print "%s 用戶注冊成功!!!" % (name) def UserLogin(): print "用戶登錄界面".center(50, '*') trycount = 0 while trycount < 3: name = raw_input("登錄用戶名:") if name not in userinfo: print "用戶未注冊" break password = raw_input("登錄密碼:") trycount += 1 if password == userinfo[name]['password']: print "恭喜%s登錄成功" % (name) break else: print "請輸入正確的用戶名或密碼!" else: print "已登錄三次,請稍后再試" def DeleteUser(): print "用戶注銷界面".center(50, '*') name = raw_input("注銷用戶名:") if name not in userinfo: print "用戶未注冊" else: password = raw_input("登錄密碼:") if password == userinfo[name]['password']: userinfo.pop(name) print "恭喜注銷%s成功" % (name) def UserInfo(): for key, value in userinfo.items(): print "用戶:%s" % (key), print "性別:%d" % (value['gender']), print "郵箱:%s" % (value['email']), print "年齡:%s" % (value['age']), print "\n\n" def main(): while True: print info choice = raw_input("Choice:").strip() if choice == "1": CreateUser() elif choice == "2": UserLogin() elif choice == "3": DeleteUser() elif choice == "4": UserInfo() elif choice == "5": exit() else: print "輸入正確的選擇" main()
更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解Python常用標(biāo)準(zhǔn)庫之os模塊與shutil模塊
os系統(tǒng)模塊與shutil文件操作模塊是Python常用的標(biāo)準(zhǔn)庫,本文將通過示例詳細(xì)講解一下二者的使用,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-06-06python中shapefile庫讀取shapefile文件信息
本文主要介紹了python中shapefile庫讀取shapefile文件信息,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06Python3.7 pyodbc完美配置訪問access數(shù)據(jù)庫
最近小編需要學(xué)習(xí)python連接access數(shù)據(jù)庫,發(fā)現(xiàn)很多朋友推薦pyodbc,那么這篇文章就先為大家介紹一下Python3.7下pyodbc的配置方法2019-10-10Python實(shí)現(xiàn)人臉識別并進(jìn)行視頻跟蹤打碼
這篇文章主要為大家詳細(xì)介紹了如何利用Python實(shí)現(xiàn)人臉識別并進(jìn)行視頻跟蹤打碼效果,羞羞的畫面統(tǒng)統(tǒng)打上馬賽克,感興趣的小伙伴可以了解一下2023-03-03NumPy實(shí)現(xiàn)從已有的數(shù)組創(chuàng)建數(shù)組
本文介紹了NumPy中如何從已有的數(shù)組創(chuàng)建數(shù)組,包括使用numpy.asarray,numpy.frombuffer和numpy.fromiter方法,具有一定的參考價值,感興趣的可以了解一下2024-10-10python+html文字點(diǎn)選驗證碼加固安全防線
這篇文章主要為大家介紹了python文字點(diǎn)選驗證碼加固安全防線實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09Python隨手筆記之標(biāo)準(zhǔn)類型內(nèi)建函數(shù)
Python提供了一些內(nèi)建函數(shù)用于基本對象類型:cmp(),repr(),str(),type()和等同于repr()的(' ')操作符,本文給大家分享Python隨手筆記之標(biāo)準(zhǔn)類型內(nèi)建函數(shù),對python內(nèi)建函數(shù)相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2015-12-12