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)提 ...
随机推荐
- rsyslog 直接读取日志,当日志截断后,不会继续发送
rsyslog web机器上日志被截断,那么就不会发送到rsyslog服务器 因为imfile记录了offset,然后你直接>导致offset还没到
- jdk、jre与jvm的区别与联系
为了学习数据库,重装了系统,之前前一直在用eclipse,现在准备换成myeclipse,这之前当然需要重新设置环境变量,顺手写下有关jdk.jre与jvm的区别与联系以供交流参考. 首先来说一下JD ...
- josscrowcroft / Simple-JavaScript-DOM-Inspector
josscrowcroft / Simple-JavaScript-DOM-Inspector josscrowcroft / Simple-JavaScript-DOM-Inspector
- Java图形化界面设计——布局管理器之FlowLayout(流式布局)
一.布局管理器所属类包 所属类包 布局管理器名称 说明 Java.awt FlowLayout(流式布局) 组件按照加入的先后顺序按照设置的对齐方式从左向右排列,一行排满到下一行开始继续排列 Bord ...
- ubuntu12.04下 安装虚拟主机
Ubuntu Linux 方法一 一.修改/etc/apache2/sites-available/ 1. 打开目录 /etc/apache2/sites-available/, 发现 default ...
- Javascript数组的声明
var cars=new Array(); cars[0]="Audi"; cars[1]="BMW"; cars[2]="Volvo"; ...
- list-style:none outside none;的作用
今天在论坛里面看到一篇文章,讲的是以前忽略的一个问题.就是当ul里面有float和display:inline,在ie6.ie7里面会有一些问题.一般对ul进行reset也好,或是设置ul的样式时,往 ...
- hdu 5104 Primes Problem(prime 将三重循环化两重)
//宁用大量的二维不用量小的三维 #include <iostream> #include<cstdio> #include<cstring> using name ...
- JS中的replace方法
JavaScript中replace() 方法如果直接用str.replace("-","!") 只会替换第一个匹配的字符. 而str.replace(/\-/ ...
- 现在输入 n 个数字, 以逗号, 分开; 然后可选择升或者 降序排序;
/* 现在输入 n 个数字, 以逗号, 分开: 然后可选择升或者 降序排序: */ import java.util.*; public class bycomma{ public static St ...