#!/usr/bin/env python
# coding:utf-8
"""
@Name: user_login.py
@Author: wrh
@Date: 1/6/17
@Connect: [email protected]
@DESC:
綜合考察練習:
user_info = {
'westos':{
'username':"westos",
"password":"",
"gender":""
}
}
用戶登陸管理系統:
1. 註冊新用戶
username
password
gender
email
age
2. 用戶登陸
username
password
3. 註銷用戶
username
password
4. 顯示用戶信息
5. 退出系統
1. 用戶名和密碼分別保存在列表中;
2. 用戶登錄時,判斷該用戶是否註冊;
2. 用戶登錄時,爲防止黑客暴力破解, 僅有三次機會;
3. 如果登錄成功,顯示登錄成功(exit(), break).
"""
info = """
用戶登錄管理系統
1. 註冊新用戶
2. 用戶登錄
3. 用戶註銷
4. 用戶信息顯示
5. 退出系統
"""
userinfo = {
'root': {
'name': 'root',
'password': 'root',
'gender': 1,
'email': '',
'age': 12
},
}
gender_choice = [0, 1, 2]
def CreateUser():
print "註冊用戶界面".center(100, '*')
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(100, '*')
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(100, '*')
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()
python練習之用戶管理系統
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.