您的位置:首页 > 其它

day1作业脚本

2016-01-07 23:59 288 查看
1.编写登录接口:

- 输入用户名和密码

- 认证成功后显示欢迎信息

- 输错三次后锁定

2.编写多级菜单

- 三级菜单

- 可依次进入子菜单

第一次写python脚本,因为没有学到函数,所以写的有点糙和繁琐,我用自己学到的知识来实现这些需求。大家也可试一试。

#!/usr/bin/env python
#NameFile:test.py
#Import time module
import time
import sys
#Define a number of variables
sum = 0
H = {'1':'白石桥','2':'东直门','3':'复兴路'}
K = {'1':'灵石路','2':'宝山路','3':'康乐路'}
P = {'1':'和平路','2':'辽宁路','3':'新华路'}
J = {'1':'大井湾','2':'王家湾','3':'茅溪村'}
B = {'1':'海淀区','2':'朝阳区','3':'东城区','4':'西城区'}
S = {'1':'黄浦区','2':'虹口区','3':'长宁区','4':'徐汇区'}
T = {'1':'和平区','2':'河东区','3':'河北区','4':'河西区'}
C = {'1':'江北区','2':'长寿区','3':'荣昌区','4':'巴南区'}
City = {
'1':'北京市',
'2':'上海市',
'3':'天津市',
'4':'重庆市',
}
#Registered account
user = input("User:").strip()
if len(user) == 0 :
print ("User cannot be empty!!!")
elif len(user) > 6:
print ("Your username is too long!!")
passwd = input("Passwd:")
if len(passwd) == 0 :
print ("Passwd cannot be empty!!!")
elif len(passwd) > 6:
print ("You set the password is too long!!")
#Format the user's account and password
list = """
Your account password is as follows:
user:%s
passwd:%s"""%(user,passwd)
print (list)
print ("Congratulations on your registration,Please login again after five seconds.")
#Wait five seconds to allow the user to re-enter
time.sleep(5)
#Please login again
while sum < 3:
User = input("please you input user:").strip()
if len(User) == 0 :
print ("User cannot be empty!!!")
elif len(User) > 6:
print ("Your username is too long!!")
Passwd = input("please you input passwd:")
if len(Passwd) == 0 :
print ("paswd cannot be empty!!!")
elif len(Passwd) > 6:
print ("You set the password is too long!!")
if User == user and Passwd == passwd:
print ("Welcome you to log in.After five seconds to enter the selection interface")
break
else:
print ("Your account or password is incorrect. Please log in again.!!!")
#Number of users log on to count more than three times to lock the account
sum += 1
if sum > 4:
print ("You log in too many, will lock your user!!!!")
time.sleep(5)
for k,v in City.items():
print (k,v)
while True:
print ('Q:退出')
A = input('Please select:').strip()
if A == '1':
for k,v in B.items():
print (k,v)
print ('Q:退出')
G = input ('Please continue to choose:').strip()
if G == '1':
for k,v in H.items():
print (k,v)
print ('Q:退出')
Y = input ('please continue:').strip()
if Y == '1':
print ('You choose is:',H['1'])
sys.exit()
elif Y == '2':
print ('You choose is:', H['2'])
sys.exit()
elif Y == '3':
print ('You choose is:',H['3'])
sys.exit()
elif Y == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if G == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if A == '2':
for k,v in S.items():
print (k,v)
print ('Q:退出')
G = input ('Please continue to choose:').strip()
if G == '1':
for k,v in K.items():
print (k,v)
print ('Q:退出')
Y = input ('please continue:').strip()
if Y == '1':
print ('You choose is:',K['1'])
sys.exit()
elif Y == '2':
print ('You choose is:', K['2'])
sys.exit()
elif Y == '3':
print ('You choose is:',K['3'])
sys.exit()
elif Y == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if G == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if A == '3':
for k,v in T.items():
print (k,v)
print ('Q:退出')
G = input ('Please continue to choose:').strip()
if G == '1':
for k,v in P.items():
print (k,v)
print ('Q:退出')
Y = input ('please continue:').strip()
if Y == '1':
print ('You choose is:',P['1'])
sys.exit()
elif Y == '2':
print ('You choose is:', P['2'])
sys.exit()
elif Y == '3':
print ('You choose is:',P['3'])
sys.exit()
elif Y == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if G == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if A == '4':
for k,v in C.items():
print (k,v)
print ('Q:退出')
G = input ('Please continue to choose:').strip()
if G == '1':
for k,v in J.items():
print (k,v)
print ('Q:退出')
Y = input ('please continue:').strip()
if Y == '1':
print ('You choose is:',J['1'])
sys.exit()
elif Y == '2':
print ('You choose is:', J['2'])
sys.exit()
elif Y == '3':
print ('You choose is:',J['3'])
sys.exit()
elif Y == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if G == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if A == 'Q':
print ('Welcome to come again next time.')
sys.exit()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: