题目:

1.输入用户名密码
2.认证成功后显示欢迎信息
3.输错三次后锁定

 #!/usr/bin/env python
import sys,pickle
account = {'wyh':123,'cloudsea':456}
l =[]
i = 0
j = 0
f1 = open('lock.txt','r')
p = f1.readlines()
for line in p:
s = line.strip('\n')
l.append(s)
f1.close()
while True:
name = input('Please input your account:').strip()
if name not in account.keys():
print ('your account error,please input agen!')
i += 1
if i == 3:
print('You tried too many times!')
sys.exit()
continue
elif name in l:
print('Your account has been locked!')
sys.exit()
while True:
passd = int(input('Password:'))
if passd != account[name]:
print('your password error,please try agen!')
j += 1
if j == 3:
f = open('lock.txt','a')
f.write(name + '\n')
f.flush()
f.close()
print('Your account is locked, please contact your administrator!')
sys.exit()
continue
break
break
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

  

python 练习1的更多相关文章

  1. Python中的多进程与多线程(一)

    一.背景 最近在Azkaban的测试工作中,需要在测试环境下模拟线上的调度场景进行稳定性测试.故而重操python旧业,通过python编写脚本来构造类似线上的调度场景.在脚本编写过程中,碰到这样一个 ...

  2. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  3. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

  4. JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议

    软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...

  5. 可爱的豆子——使用Beans思想让Python代码更易维护

    title: 可爱的豆子--使用Beans思想让Python代码更易维护 toc: false comments: true date: 2016-06-19 21:43:33 tags: [Pyth ...

  6. 使用Python保存屏幕截图(不使用PIL)

    起因 在极客学院讲授<使用Python编写远程控制程序>的课程中,涉及到查看被控制电脑屏幕截图的功能. 如果使用PIL,这个需求只需要三行代码: from PIL import Image ...

  7. Python编码记录

    字节流和字符串 当使用Python定义一个字符串时,实际会存储一个字节串: "abc"--[97][98][99] python2.x默认会把所有的字符串当做ASCII码来对待,但 ...

  8. Apache执行Python脚本

    由于经常需要到服务器上执行些命令,有些命令懒得敲,就准备写点脚本直接浏览器调用就好了,比如这样: 因为线上有现成的Apache,就直接放它里面了,当然访问安全要设置,我似乎别的随笔里写了安全问题,这里 ...

  9. python开发编译器

    引言 最近刚刚用python写完了一个解析protobuf文件的简单编译器,深感ply实现词法分析和语法分析的简洁方便.乘着余热未过,头脑清醒,记下一点总结和心得,方便各位pythoner参考使用. ...

  10. 关于解决python线上问题的几种有效技术

    工作后好久没上博客园了,虽然不是很忙,但也没学生时代闲了.今天上博客园,发现好多的文章都是年终总结,想想是不是自己也应该总结下,不过现在还没想好,等想好了再写吧.今天写写自己在工作后用到的技术干货,争 ...

随机推荐

  1. [UE4]Scale Box:缩放容器

    一.Scale Box只能有一个子控件,再拖放一控件进去是不行的. 二.Scale Box缩放保持长宽比例 三. Scale Box.Strectching.Strectch:拉伸设置.  Scale ...

  2. alertjs Documentation

    原文地址:https://github.com/PaulNieuwelaar/alertjs/wiki/Documentation#alertshow For version 3.0 document ...

  3. 换上 SansForgetica-Regular 字体,增加记忆能力

    最近澳大利亚的RMIT(皇家墨尔本理工大学) 搞出来这么个字体,号称能增强记忆,原理是通过难以识别的字体,让人提起精神去识别,从而记忆更深刻. 果断弄了个试试. 安装过程: 下载字体文件 点这里去下载 ...

  4. LINUX PID 1 和 SYSTEMD

    要说清 Systemd,得先从Linux操作系统的启动说起.Linux 操作系统的启动首先从 BIOS 开始,然后由 Boot Loader 载入内核,并初始化内核.内核初始化的最后一步就是启动 in ...

  5. 小程序打开pdf

    wx.downloadFile({ url:"https://xxxxxx.pdf", success(res){ console.log(res) let data = res. ...

  6. Oracle 学习笔记(六)

    Oracle 数据库常用的闪回sql 语句及其它操作语句: --Oracle 数据库dml sql -- 查看当前用户所拥有的表 select * from tab; --表空间,auto: 自动管理 ...

  7. 学习笔记:SASS

    SASS: http://www.sass.hk/sass-course.html  SASS 2015-10-10 http://sass.bootcss.com/docs/sass-referen ...

  8. orcal - 单行函数

    虚拟表:dual 转大写 select UPPER('hellow') from dual; 转小写 select lower(ename) from emp; cmd 输入数据 select * f ...

  9. 20165304第4次实验《Android程序设计》实验报告

    一.实验报告封面 课程:Java程序设计 班级:1653班 姓名:李松杨 学号:20165304 指导教师:娄嘉鹏 实验日期:2018年5月14日 实验时间:15:35 - 17:15 实验序号:实验 ...

  10. Java 就业班 Web框架