python 练习1
题目:
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的更多相关文章
- Python中的多进程与多线程(一)
一.背景 最近在Azkaban的测试工作中,需要在测试环境下模拟线上的调度场景进行稳定性测试.故而重操python旧业,通过python编写脚本来构造类似线上的调度场景.在脚本编写过程中,碰到这样一个 ...
- Python高手之路【六】python基础之字符串格式化
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- Python 小而美的函数
python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况 any any(iterable) ...
- JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议
软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...
- 可爱的豆子——使用Beans思想让Python代码更易维护
title: 可爱的豆子--使用Beans思想让Python代码更易维护 toc: false comments: true date: 2016-06-19 21:43:33 tags: [Pyth ...
- 使用Python保存屏幕截图(不使用PIL)
起因 在极客学院讲授<使用Python编写远程控制程序>的课程中,涉及到查看被控制电脑屏幕截图的功能. 如果使用PIL,这个需求只需要三行代码: from PIL import Image ...
- Python编码记录
字节流和字符串 当使用Python定义一个字符串时,实际会存储一个字节串: "abc"--[97][98][99] python2.x默认会把所有的字符串当做ASCII码来对待,但 ...
- Apache执行Python脚本
由于经常需要到服务器上执行些命令,有些命令懒得敲,就准备写点脚本直接浏览器调用就好了,比如这样: 因为线上有现成的Apache,就直接放它里面了,当然访问安全要设置,我似乎别的随笔里写了安全问题,这里 ...
- python开发编译器
引言 最近刚刚用python写完了一个解析protobuf文件的简单编译器,深感ply实现词法分析和语法分析的简洁方便.乘着余热未过,头脑清醒,记下一点总结和心得,方便各位pythoner参考使用. ...
- 关于解决python线上问题的几种有效技术
工作后好久没上博客园了,虽然不是很忙,但也没学生时代闲了.今天上博客园,发现好多的文章都是年终总结,想想是不是自己也应该总结下,不过现在还没想好,等想好了再写吧.今天写写自己在工作后用到的技术干货,争 ...
随机推荐
- ECMAScript 6 学习总结
1.什么是ES6? 简单的说 ES6 的第一个版本,在2015年6月发布了,正式名称就是<ECMAScript 2015标准>(简称 ES2015)在2016年6月,小幅修订的<EC ...
- Vsftp安装及配置主动模式/被动模式
第一章.前言 FTP的主动模式(active mode)和被动模式(passive mode) 大多数的TCP服务是使用单个的连接,一般是客户向服务器的一个周知端口发起连接,然后使用这个连接进行通讯 ...
- java编程思想(1)--对象导论
对象导论: 1.1 抽象过程 所有的语言都有抽象机制,抽象是解决复杂问题的根本方法.例如:汇编语言是对底层机器的轻微抽象.命令式语言(如:FORTRAN.BASIC.C)又是对汇编语言的抽象. jav ...
- 清除eclipse,STS workspace历史记录
记一下 打开eclipse下的/configuration/.settings目录 修改文件org.eclipse.ui.ide.prefs文件 把RECENT_WORKSPACES这项修改为你需要的 ...
- python——位运算之进制转化
>>> a=0b001100 >>> a 12 >>> b=0o001100 >>> b 576 >>> c= ...
- java网络编程-单线程服务端与客户端通信
该服务器一次只能处理一个客户端请求;p/** * 利用Socket进行简单服务端与客户端连接 * 这是服务端 */public class EchoServer { private ServerSoc ...
- ABAP-加密解密
report zco_test. data:o_encryptor type ref to cl_hard_wired_encryptor, o_cx_encrypt_error type ref t ...
- 2018面向对象程序设计(Java)第17周学习指导及要求
2018面向对象程序设计(Java)第17周学习指导及要求(2018.12.20-2018.12.23) 学习目标 (1) 掌握线程同步的概念及实现技术: (2) Java线程综合编程练习 学习资 ...
- Swagger注解
swagger注解说明 1.与模型相关的注解,用在bean上面 @ApiModel:用在bean上,对模型类做注释: @ApiModelProperty:用在属性上,对属性做注释 2.与接口相关的注 ...
- Linux - 操作系统
操作系统(科普章节) 目标 了解操作系统及作用 1. 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自 ...