题目:

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. 知识点:Mysql 基本用法之函数

    函数 MySQL中提供了许多内置函数 例如: sql 内置函数: 一.数学函数 ROUND(x,y) 返回参数x的四舍五入的有y位小数的值 RAND() 返回0到1内的随机值,可以通过提供一个参数(种 ...

  2. Java执行JavaScript代码

    Java执行JavaScript代码 这篇文章主要为大家详细介绍了Java执行JavaScript代码的具体操作方法,感兴趣的小伙伴们可以参考一下 我们要在Java中执行JavaScriptMetho ...

  3. 在Tomcat7.0中设置默认服务器和不加端口名访问

    前言 昨天买了域名,服务器,然后搭建了环境,然后想他通过默认的端口,不用端口就访问. 设置WEB项目的欢迎页 在WEB-INF文件夹下有个web.xml文件(最近新建的项目不包含此文件,可以手动新建) ...

  4. JavaScript倒计时实现

    /** * 倒计时函数 * @param {String}} endTime 终止时间戳 */ const countDown = (endTime, callback) => { const ...

  5. 无法启动 nexus 服务,错误1067:进程意外终止。java环境变量设置技巧。

    Nexus启动失败 wrapper.log记载: 无支持版本 51.0,版本51.0指的是Java1.7. 分析: nexus版本为2.14.8,适用JRE版本为1.7. 已配置JAVA_HOME为1 ...

  6. SQLite在Android程序中的使用方法,SQLite的增删查改方法

    Sqlite: 1.一款用来实现本地数据存储的轻量级数据管理工具,是众多用来实现数据库管理的工具之一. 2.Android已经将SQLite的代码功能吸收在它的系统中,我们可以直接在Android程序 ...

  7. source tree常用功能

    参考地址: https://blog.csdn.net/weixin_39568744/article/details/81413198

  8. LevelDB源码分析-sstable的Block

    sstable中的Block(table/block.h table/block.cc table/block_builder.h table/block_builder.cc) sstable中的b ...

  9. 移动端过禁止输入emoji表情实现方案

    最近手头上的项目有一个需求就是输入框不能输入表情,然后就各种在网上找资料,网上好多人给的方案是: str = str.replace(/\uD83C[\uDF00-\uDFFF]|\uD83D[\uD ...

  10. lvs+nginx负载均衡

    1       学习目标 掌握什么是负载均衡及负载均衡的作用和意义. 了解lvs负载均衡的三种模式. 了解lvs-DR负载均衡部署方法. 掌握nginx实现负载均衡的方法. 掌握lvs+nginx负载 ...