实现用户的登录注册

import json
def login(acc_data):
count = 0
user = input("account:")
passwd = input("password:")
while count < 3:
with open("database", "r") as db:
d = json.loads(db.read())
if user == d.get("username") and passwd == d.get("password"):
print("login successfully")
break
else:
print("Incorrect user name or password")
count += 1


def regist(acc_data):
user = input("usrname>>>")
passwd = input("password>>>")
temp = {

"username" : user,
"password" : passwd,
}
data = json.dumps(temp)
with open("database","a") as db:

db.write(data+"\n")



def start(acc_data):

menu = """
"1>>>登录",
"2>>>注册",
"3>>>退出"
"""

menu_dict = {
"1": login,
"2": regist,

}
exit_flag = False
while not exit_flag:
print(menu)
user_option = input(">>:").strip()
if user_option in menu_dict:
menu_dict[user_option](acc_data)
elif user_option == "3":
print("Welcome to again")
break

start(1)

转载于:https://www.cnblogs.com/langjitanya/p/10961139.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值