python第一期

python课时第一周:_username = 'alex'
_password = 'abc123'
username = input("username:")
password = input("paaword:")
if username ==_username and password == _password:
print("welcome to us system")
else:
print("error")判断密码与账号是否正确。count =0;
old_boy = 56
while count<3:
guess_age = int(input("guess_age:"))
count = count +1
if guess_age == old_boy:
print("yes,you winner")
break
elif guess_age < old_boy:
print("smaller..")
else:
print("bigger..")
else:
print("you have guess too many times, fuck off...")一个判断大小的小游戏,判断三次,这是博客登陆的一个前驱模式。

#Author lipengfei
#coding --utf-8---
lock_file = open('file_lock.txt','r+')
user_file = open('username_file.txt','r+')
count = 0

cmd = input('''
1:登陆系统
2.推出系统
......
请输入你的操作:''')
if cmd.isdigit() and int(cmd) == 2:
exit()
elif cmd.isdigit() and int(cmd) == 1:
while count<3 :
username = input('请输入您的用户名:')
count = count +1
for i in lock_file.readlines():
i = i.split()
if username in i[0] :
print('对不起%s已锁定'%username)
exit()


match = False
for j in user_file.readlines() :
user,password = j.strip('\n').split()
if username ==user:
passwd = input('请输入密码:')
if password == passwd :
print('用户名和密码正确')
match = True

elif passwd != password :
for i in range(0,2) :
passwd = input('密码错误,请重新输入....')
if password == passwd :
print('用户名和密码正确')
match = True
break
if username != user :
print('您输入的用户名错误')
exit()
elif match == False :
print('密码和用户名不匹配次数超过三次,已锁定')
lock_file.write('%s \n'%username)
lock_file.close()
user_file.close()
exit()
elif match == True :
print('登陆成功')
break
else:
print("无效选择,程序退出")
exit()#输错三次之后进行锁定  

欢迎大家测试

猜你喜欢

转载自www.cnblogs.com/lpflpf/p/9021885.html