python作业
# coding = utf-8#
black_name = open("black_name.txt", "w")
account = open("account.txt", "w")
account_NAME = open("account_name.txt", "w")
def string_check(filenumber, string):
if filenumber == 1:
temp_file = open("black_name.txt", "r")
elif filenumber == 2:
temp_file = open("account.txt", "r")
else:
temp_file = open("account_name.txt", "r")
temp_file_content = temp_file.readline()
temp_file_content = temp_file_content.strip('\n')
while len(temp_file_content):
if temp_file_content == string:
return 1
else:
temp_file_content = temp_file.readline()
temp_file_content = temp_file_content.strip('\n')
return 0
def logo_in():
temp_account_name = input("请输入您的账户:")
black_name = open("black_name.txt", "r")
print("测试" + str(string_check(1, temp_account_name)))
if string_check(1, temp_account_name) == 1:
print("请联系管理员")
return
try_time = 3
account = open("account.txt", "r")
while try_time:
temp_account_password = input("请输入您的账户密码:" + "剩余次数" + str(try_time))
temp_account = temp_account_name + " " + temp_account_password
if string_check(2,temp_account) == 1:
print("登录成功")
return
else:
try_time -= 1
black_name = open("black_name.txt", "a")
black_name.writelines(temp_account_name + '\n')
black_name.close()
print("请联系管理员!")
def regist():
account_NAME = open("account_name.txt", "r")
print("---------注册---------")
account_name = input("请输入您的用户名:")
while True:
ACCOUNT_NAME_ACCESS = 1
if string_check(3, account_name) == 1:
account_name = input("用户名已被占用:")
ACCOUNT_NAME_ACCESS = 0
if ACCOUNT_NAME_ACCESS == 1:
break
account_NAME = open("account_name.txt", "a")
account_NAME.writelines(account_name + '\n')
account_NAME.close()
print("账号可用!!")
while True:
account_password = input("请输入您的密码:")
if account_password.isalnum() == False:
while True:
account_password = input("密码只能包含数字和大小写字母,请再次输入:")
if account_password.isalnum() == True:
break
account_password_temp = input("请再一次输入您的密码:")
if account_password != account_password_temp:
print("密码不一致!")
else:
break
personal_account = [account_name + " " + account_password + '\n']
account = open("account.txt", "a")
account.writelines(personal_account)
account.close()
print("注册成功!!")
def main():
while True:
content = input("""
******************************
操作编码 操作
【0】 注册
【1】 登录
******************************
""")
if (content == "0"):
regist()
elif (content == "1"):
logo_in()
else:
content = input("出错了,请重新输入:")
main()