day1作业脚本
1.编写登录接口:
- 输入用户名和密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
#!/usr/bin/env python
# -*- coding:utf-8 -*- import sys,os dir = os.getcwd() Count = 0 STATUS = True
while STATUS:
L_user = input("you username:").strip()
with open(dir+"\lock.txt","r+") as f:
for n in f.readlines():
if L_user == n.strip("\n"):
print("username is lock!!!")
sys.exit()
L_passwd = input("you passwd:")
with open(dir+"\passwds.txt","r+") as f1:
for line in f1.readlines():
user,passd = line.strip("\n").split(":")
if L_user == user and L_passwd ==passd:
print("Welcome to login successfully")
sys.exit()
else:
print("login faile")
Count += 1
if Count == 3:
print("sorry ,then three time ,username lock!!!")
with open(dir+"\lock.txt","a+") as f2:
f2.write(L_user+"\n")
STATUS = False
2.编写多级菜单
- 三级菜单
- 可依次进入子菜单
第一次写python脚本,因为没有学到函数,所以写的有点糙和繁琐,我用自己学到的知识来实现这些需求。大家也可试一试。
#!/usr/bin/env python
# -*- coding:utf-8 -*- import sys meau = {
"北京":{
"通州":["梨园","果园","土桥"],
"朝阳":["将台","望京","关庄"],
"海淀":["色色","吸收","里是"]
},
"天津":{
"滨海":["但是","分手","而是"],
"光华":["厚爱","感觉","色鬼"],
"经济":["回来","反对","沟通"]
},
"河北":{
"邯郸":["是啊","在啊","怕看"],
"邢台":["个是","的个","是和"],
"保定":["先动","个他","不发"]
},
} Shi = []
Status = True
try:
while Status:
for k in meau:
print(k)
choose = input("b:back,q:quie,choose:")
if choose in meau:
Shi.append(meau)
meau = meau[choose]
elif choose == "b":
if Shi:
meau = Shi.pop()
elif choose == "q":
Status = False
else:
print("input error")
except TypeError as e:
print(choose)
#!/usr/bin/env python
#NameFile:test.py
#Import time module
import time
import sys
#Define a number of variables
sum = 0
H = {'':'白石桥','':'东直门','':'复兴路'}
K = {'':'灵石路','':'宝山路','':'康乐路'}
P = {'':'和平路','':'辽宁路','':'新华路'}
J = {'':'大井湾','':'王家湾','':'茅溪村'}
B = {'':'海淀区','':'朝阳区','':'东城区','':'西城区'}
S = {'':'黄浦区','':'虹口区','':'长宁区','':'徐汇区'}
T = {'':'和平区','':'河东区','':'河北区','':'河西区'}
C = {'':'江北区','':'长寿区','':'荣昌区','':'巴南区'}
City = {
'':'北京市',
'':'上海市',
'':'天津市',
'':'重庆市',
}
#Registered account
user = input("User:").strip()
if len(user) == 0 :
print ("User cannot be empty!!!")
elif len(user) > 6:
print ("Your username is too long!!")
passwd = input("Passwd:")
if len(passwd) == 0 :
print ("Passwd cannot be empty!!!")
elif len(passwd) > 6:
print ("You set the password is too long!!")
#Format the user's account and password
list = """
Your account password is as follows:
user:%s
passwd:%s"""%(user,passwd)
print (list)
print ("Congratulations on your registration,Please login again after five seconds.")
#Wait five seconds to allow the user to re-enter
time.sleep(5)
#Please login again
while sum < 3:
User = input("please you input user:").strip()
if len(User) == 0 :
print ("User cannot be empty!!!")
elif len(User) > 6:
print ("Your username is too long!!")
Passwd = input("please you input passwd:")
if len(Passwd) == 0 :
print ("paswd cannot be empty!!!")
elif len(Passwd) > 6:
print ("You set the password is too long!!")
if User == user and Passwd == passwd:
print ("Welcome you to log in.After five seconds to enter the selection interface")
break
else:
print ("Your account or password is incorrect. Please log in again.!!!")
#Number of users log on to count more than three times to lock the account
sum += 1
if sum > 4:
print ("You log in too many, will lock your user!!!!")
time.sleep(5)
for k,v in City.items():
print (k,v)
while True:
print ('Q:退出')
A = input('Please select:').strip()
if A == '':
for k,v in B.items():
print (k,v)
print ('Q:退出')
G = input ('Please continue to choose:').strip()
if G == '':
for k,v in H.items():
print (k,v)
print ('Q:退出')
Y = input ('please continue:').strip()
if Y == '':
print ('You choose is:',H[''])
sys.exit()
elif Y == '':
print ('You choose is:', H[''])
sys.exit()
elif Y == '':
print ('You choose is:',H[''])
sys.exit()
elif Y == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if G == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if A == '':
for k,v in S.items():
print (k,v)
print ('Q:退出')
G = input ('Please continue to choose:').strip()
if G == '':
for k,v in K.items():
print (k,v)
print ('Q:退出')
Y = input ('please continue:').strip()
if Y == '':
print ('You choose is:',K[''])
sys.exit()
elif Y == '':
print ('You choose is:', K[''])
sys.exit()
elif Y == '':
print ('You choose is:',K[''])
sys.exit()
elif Y == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if G == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if A == '':
for k,v in T.items():
print (k,v)
print ('Q:退出')
G = input ('Please continue to choose:').strip()
if G == '':
for k,v in P.items():
print (k,v)
print ('Q:退出')
Y = input ('please continue:').strip()
if Y == '':
print ('You choose is:',P[''])
sys.exit()
elif Y == '':
print ('You choose is:', P[''])
sys.exit()
elif Y == '':
print ('You choose is:',P[''])
sys.exit()
elif Y == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if G == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if A == '':
for k,v in C.items():
print (k,v)
print ('Q:退出')
G = input ('Please continue to choose:').strip()
if G == '':
for k,v in J.items():
print (k,v)
print ('Q:退出')
Y = input ('please continue:').strip()
if Y == '':
print ('You choose is:',J[''])
sys.exit()
elif Y == '':
print ('You choose is:', J[''])
sys.exit()
elif Y == '':
print ('You choose is:',J[''])
sys.exit()
elif Y == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if G == 'Q':
print ('Welcome to come again next time.')
sys.exit()
if A == 'Q':
print ('Welcome to come again next time.')
sys.exit()
#!/usr/bin/env python
# -*- coding:utf-8 -*- import sys meau = {
"北京":{
"通州":["梨园","果园","土桥"],
"朝阳":["将台","望京","关庄"],
"海淀":["色色","吸收","里是"]
},
"天津":{
"滨海":["但是","分手","而是"],
"光华":["厚爱","感觉","色鬼"],
"经济":["回来","反对","沟通"]
},
"河北":{
"邯郸":["是啊","在啊","怕看"],
"邢台":["个是","的个","是和"],
"保定":["先动","个他","不发"]
},
} Shi = []
Status = True
try:
while Status:
for k in meau:
print(k)
choose = input("b:back,q:quie,choose:")
if choose in meau:
Shi.append(meau)
meau = meau[choose]
elif choose == "b":
if Shi:
meau = Shi.pop()
elif choose == "q":
Status = False
except TypeError as e:
print(choose)
day1作业脚本的更多相关文章
- 自动备份并保存最近几天的SQL数据库作业脚本
DECLARE @filename VARCHAR(255) DECLARE @date DATETIME SELECT @date=GETDATE() SELECT @filename = 'G:\ ...
- Day1作业要求
Day1作业 作业需求 博客 模拟登录 三级菜单 博客地址 杨振伟Day1博客地址 模拟登录 1.程序说明 实现功能如下 用户输入密码,密码验证后登录成功 用户登录成功后提示登录信息 用户输入3次错误 ...
- MS SQL批量生成作业脚本方法介绍总结
在迁移或升级SQL Server数据库服务器时,很多场景下我们不能还原msdb,所以我们必须手工迁移SQL Server相关作业.如果手工生成每一个作业的脚本话,费时又费力,其实SQL Server中 ...
- day1作业--登录入口
作业概述: 编写一个登录入口,实现如下功能: (1)输入用户名和密码 (2)认证成功后显示欢迎信息 (3)输错三次后锁定 流程图: readme: 1.程序配置文件: 黑名单文件blacklist.t ...
- Python3.5 Day1作业:实现用户密码登录,输错三次锁定。
作业需求: 1.输入用户名密码 2.认证成功后显示欢迎信息 3.输错三次后锁定 实现思路: 1.判断用户是否在黑名单,如果在黑名单提示账号锁定. 2.判断用户是否存在,如果不存在提示账号不存在. 3. ...
- day1作业--三级菜单
作业概述: 写一个三级菜单 实现如下功能: (1)可依次选择进入各子菜单 (2)在每一级按“b”都可以返回上一级,按“q"都可以退出 流程图: readme: 简介: three_menu. ...
- day1作业
作业一:博客 作业二:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 作业三:多级菜单 三级菜单 可依次选择进入各子菜单 所需新知识点:列表.字典 作业一分析: readme.m ...
- day1作业--登录接口
作业:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 知识: 1.循环的使用: 2.continue,break在循环中中断的作用: 3.文件的写入,读取: 4.各基础知 ...
- day1作业二:多级菜单操作
作业二:多级菜单 (1)三级菜单 (2)可以次选择进入各子菜单 (3)所需新知识点:列表.字典 要求:输入back返回上一层,输入quit退出整个程序 思路: (1)首先定义好三级菜单字典: (2)提 ...
随机推荐
- Codeforces 706D Vasiliy's Multiset(可持久化字典树)
[题目链接] http://codeforces.com/problemset/problem/706/D [题目大意] 要求实现一个集合中的三个操作,1:在集合中加入一个元素x,2:从集合中删除一个 ...
- 项目管理:关于SVN的实践
SVN是Subversion的简称,是一个开放源码的版本号控制系统. 合作开发的时候,对SVN的使用有3个软件:SVN的server端,SVNclient(也就是Tortoise SVN,寻常chec ...
- 一个简单的文本编辑器。(是在DEV C++下写的)
//头文件// main.h #define CM_FILE_SAVEAS 9072 #define CM_FILE_EXIT 9071 #define CM_FILE_OPEN 9070 #defi ...
- Webserver管理系列:9、创password重设盘
网络时代需要记录password太多.一不留神可能会忘记.是否server的password忘记将是一件非常麻烦的事情. Windows Server 2008 它为我们创造password重设盘功能 ...
- 关于css的默认宽度
<div class="boxa"> <div class="boxb">我是div</div> </div> ...
- JS年月日三级联动下拉框日期选择代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- [SAP] 外部系统调用SAP web service用户验证的简单方法
场景: 一个Java系统调用SAP系统提供的web service,除了根据WSDL生成的代理类,调用相应方法,传入相应参数外,还等需要使用SAP提供的用户信息进行身份验证,最简单的方法是在soap请 ...
- Java 重写(Override)与重载(Overload)
1.重写(Override) 重写是子类对父类的允许访问的方法的实现过程进行重新编写!返回值和形参都不能改变.即外壳不变,核心重写! 参数列表和返回值类型必须与被重写方法相同. 访问权限必须低于父类中 ...
- BZOJ 1016: [JSOI2008]最小生成树计数( kruskal + dfs )
不同最小生成树中权值相同的边数量是一定的, 而且他们对连通性的贡献是一样的.对权值相同的边放在一起(至多10), 暴搜他们有多少种方案, 然后乘法原理. ----------------------- ...
- nodejs入门demo
demo的实例引用自:http://www.runoob.com/nodejs/nodejs-event.html, 官方文档:https://nodejs.org/dist/latest-v6.x/ ...