python练习1简易登录接口

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python练习1简易登录接口相关的知识,希望对你有一定的参考价值。

#/usr/bin/env python
# -*- coding:utf-8 -*-

import os

user_dic = {
‘jyd‘ : {‘password‘: ‘abc‘, ‘count‘: 0},
‘test‘: {‘password‘: ‘test‘, ‘count‘: 0}
}
if not os.path.isfile(‘lock‘):
open(‘lock‘,‘w‘).close()
total_error = 0
print("Exit from the username and enter : quit")
while total_error < 9 :
user = input(‘username-->:‘)
if user == ‘quit‘:
break
if user in user_dic.keys():
#看锁文件中是否有该用户,若有则被锁并重定义lock_u为yes,再跳出锁判断循环。根据lock_u的值确定用户是否被锁。
lock = open(‘lock‘, ‘r‘)
for lock_u in lock.read().split(‘\n‘):
if user == lock_u :
print(‘User %s is in a locked state‘ %user)
lock_u = ‘yes‘
break
lock.close()
if lock_u == ‘yes‘: continue
passwd = input(‘password-->:‘)
if passwd == user_dic[user][‘password‘]:
print(‘Login successfully!‘)
break
else:
print(‘Password error‘)
if user_dic[user][‘count‘] < 3:
user_dic[user][‘count‘] += 1
else:
lock = open(‘lock‘, ‘a‘)
lock.write(user+‘\n‘)
print(‘User %s has been locked‘ %user)
break
else:
print(‘Username does not exist.‘)
total_error+=1

以上是关于python练习1简易登录接口的主要内容,如果未能解决你的问题,请参考以下文章

Python练习,模拟用户登录接口

Python练习,模拟用户登录接口

Python 练习1——简易购物车

python 练习一

Python学习第二周-简易购物车练习

python简易购物车练习