python使用者管理系統,python管理系統
本文執行個體為大家分享了Python使用者管理系統的具體代碼,供大家參考,具體內容如下
使用者管理系統
1.註冊新使用者
如果註冊使用者已經存在,則報錯
需要填寫資訊: name, passwd, gender, email,age
2.使用者登入 要求同之前寫的使用者登入系統
3.登出使用者 使用者登出時,需要輸入使用者名稱和正確的使用者密碼
4.顯示使用者資訊 顯示系統中存在所有已經註冊使用者的資訊
5.退出系統
代碼如下
#!/usr/bin/env python#coding:utf-8info = """************************************************************ 使用者登入管理系統************************************************************ 1. 註冊新使用者 2. 使用者登入 3. 使用者登出 4. 使用者資訊顯示 5. 退出系統"""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()
以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。