题目:
1.输入用户名密码
2.认证成功后显示欢迎信息
3.输错三次后锁定
1 #!/usr/bin/env python 2 import sys,pickle 3 account = {'wyh':123,'cloudsea':456} 4 l =[] 5 i = 0 6 j = 0 7 f1 = open('lock.txt','r') 8 p = f1.readlines() 9 for line in p: 10 s = line.strip('\n') 11 l.append(s) 12 f1.close() 13 while True: 14 name = input('Please input your account:').strip() 15 if name not in account.keys(): 16 print ('your account error,please input agen!') 17 i += 1 18 if i == 3: 19 print('You tried too many times!') 20 sys.exit() 21 continue 22 elif name in l: 23 print('Your account has been locked!') 24 sys.exit() 25 while True: 26 passd = int(input('Password:')) 27 if passd != account[name]: 28 print('your password error,please try agen!') 29 j += 1 30 if j == 3: 31 f = open('lock.txt','a') 32 f.write(name + '\n') 33 f.flush() 34 f.close() 35 print('Your account is locked, please contact your administrator!') 36 sys.exit() 37 continue 38 break 39 break 40 print ('Welcome %s into this program!'% name)
题目二:
三级菜单
可依次进入各子菜单
选择b 返回上一级菜单
选择q 退出系统
代码如下:
#!usr/bin/env python
# encoding: utf-8
import sys
dic = {'皖':{'合肥':['A区','B区','C区','return','exit'],'芜湖':['D区','E区','F区','return','exit'],'黄山':['G区','H区','I区','return','exit']},'苏':{'南京':['J区','K区','L区','return','exit'],'无锡':['O区','P区','Q区','return','exit'],'苏州':['R区','S区','T区','return','exit']},'浙':{'杭州':['U区','V区','W区','return','exit'],'宁波':['X区','Y区','Z区','return','exit'],'温州':['1区','2区','3区','return','exit']}}
list_1 = []
list_2 = []
list_3 = []
list_4 = []
list_e = ['return','exit']
for i in dic.keys():
list_1.append(i)
for k in dic['皖'].keys():
list_2.append(k)
list_2 = list_2 + list_e
for a in dic['苏'].keys():
list_3.append(a)
list_3 = list_3 + list_e
for b in dic['浙'].keys():
list_4.append(b)
list_4 = list_4 + list_e
while True:
for j in range(len(list_1)):
print('%s.%s'%(j,list_1[j]))
N1 = int(input('Please choose a briefly name :'))
if N1 == 0:
while True:
for m in range(len(list_2)):
print('%s.%s'%(m,list_2[m]))
N2 = int(input('Please choose city Num:'))
if N2 == 0:
while True:
for n in range(len(dic['皖']['合肥'])):
print('%s.%s'%(n,dic['皖']['合肥'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 1:
while True:
for n in range(len(dic['皖']['芜湖'])):
print('%s.%s'%(n,dic['皖']['芜湖'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 2:
while True:
for n in range(len(dic['皖']['黄山'])):
print('%s.%s'%(n,dic['皖']['黄山'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 3:
break
elif N2 == 4:
sys.exit()
else:
print('Num error,please try agen!')
continue
if N1 == 1:
while True:
for m in range(len(list_3)):
print('%s.%s'%(m,list_3[m]))
N2 = int(input('Please choose city Num:'))
if N2 == 0:
while True:
for n in range(len(dic['苏']['南京'])):
print('%s.%s'%(n,dic['苏']['南京'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 1:
while True:
for n in range(len(dic['苏']['无锡'])):
print('%s.%s'%(n,dic['苏']['无锡'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 2:
while True:
for n in range(len(dic['苏']['苏州'])):
print('%s.%s'%(n,dic['苏']['苏州'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 3:
break
elif N2 == 4:
sys.exit()
else:
print('Num error,please try agen!')
continue
if N1 == 2:
while True:
for m in range(len(list_4)):
print('%s.%s'%(m,list_4[m]))
N2 = int(input('Please choose city Num:'))
if N2 == 0:
while True:
for n in range(len(dic['浙']['杭州'])):
print('%s.%s'%(n,dic['浙']['杭州'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 1:
while True:
for n in range(len(dic['浙']['宁波'])):
print('%s.%s'%(n,dic['浙']['宁波'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 2:
while True:
for n in range(len(dic['浙']['温州'])):
print('%s.%s'%(n,dic['浙']['温州'][n]))
N3 = int(input('Please back:'))
if N3 == 3:
break
elif N3 == 4:
sys.exit()
elif N3 < 3 and N3 >= 0:
continue
else:
print('Num error,please try agen!')
continue
elif N2 == 3:
break
elif N2 == 4:
sys.exit()
else:
print('Num error,please try agen!')
continue
浙公网安备 33010602011771号