# -*- coding:utf-8 -*-
input_name = input("Please input your user name : ").strip()
user_lockfile = open("user_lockfile.txt","r+")
user_file = open("user_file.txt")
user_list = user_file.readlines()
for i in range(3):
input_passwd = input("Please input your password : ").strip()
#查找被锁用户列表判断是否被锁住
if input_name in [locked_user.rstrip() for locked_user in user_lockfile.readlines()]:
print("Sorry, your account is locked!")
user_file.close()
user_lockfile.close()
exit(1)
else: #没有被锁住,查找用户列表
if input_name not in [user_record.split()[0] for user_record in user_list]:
print("Sorry, your account doesn't exist!")
user_file.close()
user_lockfile.close()
exit(2)
else: #用户存在,判断密码是否正确,正确跳出循环
input_record = input_name + ' ' + input_passwd
# print(input_record)
# print(user_file.tell()) #记录当前游标位置
if input_record in [user_record.rstrip() for user_record in user_list]:
print("Logging in...")
user_file.close()
user_lockfile.close()
exit(0)
else:#密码不正确,判断错误次数,错误三次(i=2)将用户锁住
if i == 2:
user_lockfile.write(input_name + "\n")
print("Sorry, you're locked!")
user_file.close()
user_lockfile.close()
exit(3)
else:#剩余机会数 2-i
chance = 2 - i
print("Wrong password! %s chances left!" % chance)
# -*- coding:utf-8 -*-
import time
import os
DICT_PRO = {"北京":["大兴区","朝阳区","海淀区","东城区","西城区","丰台区","通州区"],
"上海":["静安区","徐汇区","浦东新区","虹口区","普陀区","长宁区","宝山区","嘉定区","闵行区"],
"山东省":["烟台市","济南市","青岛市"],
"辽宁省":["大连市","沈阳市"],
"香港":None,
"澳门":None,
"台湾":["台北市"]}
DICT_CIT = {"烟台市":["莱山区","芝罘区","福山区","龙口市"],
"青岛市":["李沧区","台东区","崂山区"],
"济南市":["市中区","天桥区","历城区"],
"大连市":["中山区","甘井子区","沙河口区","高新园区"],
"沈阳市":["皇姑区","大东区","和平区","铁西区"]}
#将输入的数字转化成整数形式
def input_verify(choice):
if str.isdigit(choice):
choice = int(choice)
return choice
#输出框架
def framework_show(province='', city='', district=''):
os.system('cls') #清屏
print('''
######################################################
* *
* 欢迎进入省市区查询系统 *
* *
######################################################
* *
* 省份 : %s 城市 : %s 区 : %s
* *
######################################################
''' % (province, city, district))
#展示欢迎界面
def welcome_show(province='', city='', district=''):
print('''
######################################################
* *
* Welcome to %s %s %s
* *
######################################################
''' % (province, city, distr