1.首先我们要创建对象——类的实例化,定义好以后,这里将会用到__init__()和self参数, init()是一个特殊的方法,叫构造方法或者是构造函数。
from faker import Faker
class person:
def __init__(self, name, password, phone_number, address, IDcard):
self.name = name
self.password = password
self.phone_number = phone_number
self.address = address
self.IDcard = IDcard
fake = Faker(locale="zh_cn")
a = {}
person_list = []
for i in range(0, 1000):
a["name"] = fake.name()
a["password"] = fake.password()
a["phone_number"] = fake.phone_number()
a["address"] = fake.address()
a["IDcard"] = fake.ssn()
# print(name,password,phone_number,address,IDcard)
person_list.append(a)
2.下一步写登录,注册的界面,开头和结尾可以用print()来输出登录和注册:
print("------------------注册----------------")
print("----------------登录---------------------")
3.最后利用while循环语句来书写登录,注册里的内容。if条件真就返回,elif不满足就继续。break跳出循环。
print("------------------注册----------------")
flag = 1
while flag:
name = input("请输入姓名,以回车ok")
password = input("请输入密码,以回车ok")
for b in person_list:
#print(i.name)
if b["name"] == name:
print("你的账号存在,请重输!")
break
elif len(password) < 8 or len(password) > 16:
print("密码长度应在8-16位")
break
else:
print("注册成功,欢迎来到和平精英")
a["name"] = name
a["password"] =password
person_list.append(a)
# person_list.append(person(name, password, phone_number, address, IDcard))
flag = 0
break
print("----------------登录---------------------")
swich = 1
while swich:
name = input("请输入姓名,以回车ok")
password = input("请输入密码,以回车ok")
for i in person_list:
# print(i.name)
if i["name"] == name and i["password"] == password:
print("----------------------")
print(" 欢迎来到和平精英 ")
swich = 0
break
else:
print(" ")
print("账号或密码错误请重试")
break
else:
a = 0
if a <len(person_list):
continue
else:
print(" ")
print("账号或密码错误请重试")
break
4.实验结果:
------------------注册----------------
请输入姓名,以回车ok小王
请输入密码,以回车ok1234567
密码长度应在8-16位
请输入姓名,以回车ok小王
请输入密码,以回车ok12345678
注册成功,欢迎来到和平精英
----------------登录---------------------
请输入姓名,以回车ok小王
请输入密码,以回车ok12345678
----------------------
欢迎来到和平精英
Process finished with exit code 0