用戶管理
"""
1.後臺管理員只有一個用戶admin,密碼admin
2.當管理員登錄成功後,能夠管理前臺用戶信息
3.用戶信息管理包含:
添加用戶信息
刪除用戶信息
查看用戶信息
指定用戶查看密碼
退出
ctrl + / :快註釋和取消註釋
"""
def useradd():
"""
添加用戶
:return:
"""
print('添加用戶信息'.center(50, '*'))
usernew = input('請添加用戶:')
passwdnew = input('請輸入密碼:')
if usernew in usersinfo:
print('該用戶已存在')
else:
usersinfo.update({usernew:passwdnew})
print('用戶添加成功')
def userdel():
"""
刪除用戶
:return:
"""
print('刪除用戶信息'.center(50, '*'))
userdel = input('請選擇刪除用戶:')
if userdel in usersinfo:
usersinfo.pop(userdel)
print('%s用戶已刪除' % (userdel))
else:
print('用戶不存在')
def usermess():
"""
查看用戶信息
:return:
"""
print('查看用戶信息'.center(50, '*'))
print("全部用戶有:",end="")
print(usersinfo.keys())
userlook = input('請輸入你要查看的用戶:')
if userlook in usersinfo:
print('此用戶密碼爲', end=':')
print(usersinfo[userlook])
else:
print('用戶不存在')
print("管理員登錄".center(50, '*'))
inuser = input('user name:')
inpasswd = input('passwd:')
usersinfo = {"root":'redhat'}
if inuser == 'admin' and inpasswd == 'admin':
print('管理員登錄成功')
print('會員管理'.center(50, '*'))
print("""
管理員操做目錄
# 1 - 添加用戶信息
# 2 - 刪除用戶信息
# 3 - 查看用戶信息
# 4 - 退出
""")
while 1:
choice = input('請選擇你的操做:')
if choice == '1':
useradd()
elif choice == '2':
userdel()
elif choice == '3':
usermess()
elif choice == '4':
exit()
else:
print('非法請求')
else:
print('管理員登陸失敗')
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
打字遊戲
"""
"""
編寫函數,計算字符串匹配的準確率,
orginStr爲原始內容,userStr爲用戶輸入內容
"""
#
#計算正確率
def myper(sen):
count=0
oldse = "do your best"
for i,v in zip(oldse,sen):
# print(i,v)
if i==v:
count += 1
percent = count /len(oldse)*100
# print(len(oldse))
# return percent
print("正確率爲%.2f%%" %(percent))
sentence=input("please input 'do your best':")
myper(sentence)
## do my best
## do m b
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
打地鼠遊戲
"""
模擬打地鼠遊戲
假設一共有5個洞口,老鼠在裏面隨機一個洞口;
人隨機打開一個洞口,若是有老鼠,表明抓到了
若是沒有,繼續打地鼠,可是老鼠會跳到其餘洞口
"""
# 五個集合(0,1)...(4,5)
# 老鼠取值(0,1)+randint
import random
def mybeat():
holedict = {'hole0': (0, 1),
'hole1': (1, 2),
"hole2": (2, 3),
"hole3": (3, 4),
"hole4": (4, 5)
}
while True:
m = random.randint(0,4)
if 0 <= m < 1:
beat = 'hole0'
elif 1 <= m < 2:
beat = 'hole1'
elif 2 <= m < 3:
beat = 'hole2'
elif 3 <= m < 4:
beat = 'hole3'
else:
beat = 'hole4'
print(beat)
true = input("請輸入你選擇的洞口(hole0~hole4):")
if true== beat:
print("恭喜恭喜")
break
mybeat()
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)