题目1:用户管理系统V2:
用户功能如下:
welcome to xxxx system
- 1.注册:若用户存在,直接报错”name 已经存在”,若用户不存在,将用户信息保存起来,显示”注册成功”;
- 2.登陆:若用户存在,判断密码是否正确,若用户不存在,报错”name 不存在”;
- 3.注销:若用户存在,删除用户信息;若不存在,报错报错”name 不存在;
- 4.退出:break
#!/usr/bin/env python
#coding:utf-8
"""
file:login.py
date:2017-09-02 9:20 PM
author:lihang
desc:
"""
d = {"root":"westos"}
def add():
username = raw_input('username:')
if d.has_key(username):
print "%s 已经存在!" % (username)
else:
password = raw_input('password:')
d[username] = password
print "%s 注册成功!" % (username)
def info():
print "用户名\t密码"
for username, password in d.items():
print "%s\t%s" % (username, password)
def login():
trycount = 0
while True:
if trycount == 3:
print "登陆超过三次,再会,我的朋友!"
exit()
username = raw_input("username:")
if not d.has_key(username):
print "用户不存在!"
break
password = raw_input("password:")
if d[username] == password:
print "登陆成功!"
exit()
else:
print "密码错误!"
trycount += 1
def logout():
username = raw_input("username:")
if not d.has_key(username):
print "用户不存在!"
del (d[username])
while True:
print """
欢迎进入用户信息管理界面
登陆:login(L)
注册:add(A)
注销:logout(O)
显示:info(I)
退出:quit(Q)
"""
choice = raw_input("请输入你的选择:")
if choice in 'lL':
login()
continue
elif choice in 'aA':
add()
continue
elif choice in 'oO':
logout()
continue
elif choice in 'iI':
info()
continue
else:
exit()
题目2:用户管理系统V3:
d = {“name”:[]}
初始化有一个系统管理员:
用户分为两种:
用户登录:
- 登陆
- 退出
判断用户类型:
系统管理员功能:
- 1.添加用户
- 4.查看所有用户信息
- 5.退出:
普通用户功能:
- 1.查看个人信息
- 2.注销
- 2.退出
要求:
1. 根据用户身份,进入不同的管理界面;
2. 系统初始化一个系统管理员帐号;
3. 只有系统管理员可以添加用户和查看用户所有信息;
4. 普通用户只能查看个人信息,和注销帐号;
welcome to xxx system
- 1.注册:
- 2.登陆:
- 3.注销:
- 4.查看所有用户信息
- 5.退出:
#!/usr/bin/env python
#coding:utf-8
"""
file:login2.py
date:2017-09-02 9:27 PM
author:lihang
desc:
"""
d = {
"root":"westos",
"kiosk":"redhat",
}
def add():
username = raw_input('username:')
if d.has_key(username):
print "%s 已经存在!" % (username)
else:
password = raw_input('password:')
d[username] = password
print "%s 注册成功!" % (username)
def info():
print "用户名\t密码"
for username, password in d.items():
print "%s\t%s" % (username, password)
def login():
trycount = 0
while True:
if trycount == 3:
print "登陆超过三次,再会,我的朋友!"
exit()
username = raw_input("username:")
if not d.has_key(username):
print "用户不存在!"
break
password = raw_input("password:")
if d[username] == password:
print "登陆成功!"
exit()
else:
print "密码错误!"
trycount += 1
def logout():
username = raw_input("username:")
if not d.has_key(username):
print "用户不存在!"
del (d[username])
while True:
pro = """
欢迎进入用户信息管理界面
登陆:login(L)
注册:add(A)
注销:logout(O)
显示:info(I)
退出:quit(Q)
"""
dict = {
"L":login,
"A":add,
"O":logout,
"I":info,
"Q":quit,
}
while True:
choice = raw_input(pro)
dict.get(choice)()