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线上问题的几种有效技术
工作后好久没上博客园了,虽然不是很忙,但也没学生时代闲了.今天上博客园,发现好多的文章都是年终总结,想想是不是自己也应该总结下,不过现在还没想好,等想好了再写吧.今天写写自己在工作后用到的技术干货,争 ...
随机推荐
- python import引入不同路径下的模块
转载 python 包含子目录中的模块方法比较简单,关键是能够在sys.path里面找到通向模块文件的路径. 下面将具体介绍几种常用情况: (1)主程序与模块程序在同一目录下: 如下面程序结构: `- ...
- 注解:大话AOP与Android的爱恨情仇
转载:大话AOP与Android的爱恨情仇 1. AOP与OOP的区别 平时我接触多的就是OOP(Object Oriented Programming面向对象).AOP(Aspect Oriente ...
- PV、IV、UV
PV 访问量 UV 独立访客 IV 独立ip数 qps 流量
- JavaWeb——tomcat manager 403 Access Denied .You are not authorized to view this page.
403 Access Denied You are not authorized to view this page. If you have already configured the Manag ...
- Centos创建用户
1.创建用户: adduser fish 2.用户设置密码: passwd linuxidc 3.创建文件夹: mkdir fish 4.删除文件夹 rm -rf fish 5.文件夹重命名: mv ...
- Idea中类上有叉的解决方法
idea中类的头上出现X解决办法 ctrl+alt+s 在弹出的菜单上选择Compiler下的Excludes 右边会有 移除掉,点击ok, 重启idea就可以了
- JAVA 类的三大特性,封装,继承,多态 的一些发现总结
< 一 > 封装 < 二 > 继承 1,关于父类中的私有属性和方法,子类能不能访问的问题 1.1,子类不能通过继承拥有父类的私有属性和方法 1.2,子类可以从父类继承下来的 方 ...
- Caffe:如何将图片数据转换成lmdb文件
1 图片信息的转换 在caffe中经常使用的数据类型是lmdb或leveldb;不是常见的jpg,jpeg,png,tif等格式;因此,需要进行格式转换,通过输入你自己的图片目录(下有的大量图片)转换 ...
- 最适合入门的Laravel中级教程(二)用户认证
之前的初级教程主要是学习简单的增删改查: 接着的中级教程的目标是在初级教程的基础上能写出更复杂更健壮的程序: 我们先来学习 laravel 的用户认证功能: 在现代网站中基本都有用户系统: 而我们每开 ...
- mysql数据库中指定值在所有表中所有字段中的替换
MySQL数据库: 指定值在数据库中所有表所有字段值的替换(存储过程): 1.写一个存储过程,查指定数据库中所有的表名: CREATE PROCEDURE init_replace(in orig_s ...