import sys
users = []
def check_name_null(name, password, confirm_password):
if name is None or name == "":
print("用户名称不能为空!")
return False
return True
def check_user_info(name):
for u in users:
if name == u.get("username"):
return u
return None
def check_info(password, confirm_password):
if len(password) < 3:
print("对不起,密码长度不能少于3位!!")
return False
if password != confirm_password:
print("对不起,两次密码不一致!!")
return False
return True
def reg():
while True:
name = input("请输入用户名称:")
password = input("请输入用户密码:")
confirm_password = input("请再次确认用户密码:")
# 校验用户信息
if check_name_null(name, password, confirm_password) and check_info(password, confirm_password):
if check_user_info(name) is None:
user = {"username": name, "password": password}
users.append(user)
print("注册成功")
break
else:
print("对不起,该用户已存在,请重新注册!!")
else:
print("注册失败!!")
print(users)
def check_user_login(name, password):
user = check_user_info(name)
if user is None:
print("用户不存在!!!")
return False
else:
ps = user.get("password")
if ps == password:
print("登录成功")
return True
else:
print("密码错误")
return False
def login():
while True:
name = input("请输入用户名称:")
password = input("请输入用户密码:")
# 校验用户信息
if check_user_login(name, password):
return True
else:
return False
while True:
print("~ * " * 20)
print("\t\t 1、用户注册")
print("\t\t 2、用户登录")
print("\t\t 3、退出系统")
choice = input("请输入您的选择:")
if choice == "1":
reg()
elif choice == "2":
if login():
print("\t英雄商城英雄列表\n")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
print("编号 姓名 昵称 价格 库存 描述\n")
print("1 纳尔 迷失之牙 3500 100 丛林不会原谅盲目与无知\n")
print("2 锐雯 放逐之刃 4000 100 她是残忍高效的战士\n")
print("3 薇恩 暗夜猎手 3500 100 这个世界不想人们想象的那么美好\n")
print("4 扎克 生化魔人 3000 100 即使你没有脊柱,你也必须站起来\n")
print("5 杰斯 未来守护者 2500 100 武装着睿智与魅力,你的选择没有错\n")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
buy = int(input('(温馨提示)请输入您要购买的英雄编号:'))
if buy == 1:
num = int(input('请输入购买数量:'))
if num < 100:
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("英雄名称:纳尔---迷失之牙\n")
print("英雄描述:丛林不会原谅盲目与无知!\n")
print("英雄价格:3500\n")
print("插播广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
need_pay = num * 3500
print("(温馨提示)请付款:%s" % need_pay)
pay = int(input('请输入付款金额:'))
if pay >= need_pay:
amount = pay - need_pay
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("\t英雄名称:纳尔---迷失之牙\n")
print("\t英雄价格:3500\n")
print("\t应付付款:%s\n" % need_pay)
print("\t实际付款:%s\n" % pay)
print("\t找零:%s\n\n" % amount)
print("插入广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡 ")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
else:
print('无法支付!')
else:
print('输入错误或库存不足!')
if buy == 2:
num = int(input('请输入购买数量:'))
if num < 100:
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("英雄名称:锐雯---放逐之刃\n")
print("英雄描述:她是残忍高效的战士!\n")
print("英雄价格:4000\n")
print("插播广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
need_pay = num * 4000
print("(温馨提示)请付款:%s" % need_pay)
pay = int(input('请输入付款金额:'))
if pay >= need_pay:
amount = pay - need_pay
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("\t英雄名称:锐雯---放逐之刃\n")
print("\t英雄价格:4000\n")
print("\t应付付款:%s\n" % need_pay)
print("\t实际付款:%s\n" % pay)
print("\t找零:%s\n\n" % amount)
print("插入广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡 ")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
else:
print('无法支付!')
else:
print('输入错误或库存不足!')
if buy == 3:
num = int(input('请输入购买数量:'))
if num < 100:
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("英雄名称:薇恩---暗夜猎手\n")
print("英雄描述:这个世界不想人们想象的那么美好!\n")
print("英雄价格:3500\n")
print("插播广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
need_pay = num * 3500
print("(温馨提示)请付款:%s" % need_pay)
pay = int(input('请输入付款金额:'))
if pay >= need_pay:
amount = pay - need_pay
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("\t英雄名称:薇恩---暗夜猎手\n")
print("\t英雄价格:3500\n")
print("\t应付付款:%s\n" % need_pay)
print("\t实际付款:%s\n" % pay)
print("\t找零:%s\n\n" % amount)
print("插入广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡 ")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
else:
print('无法支付!')
else:
print('输入错误或库存不足!')
if buy == 4:
num = int(input('请输入购买数量:'))
if num < 100:
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("英雄名称:扎克---生化魔人\n")
print("英雄描述:即使你没有脊柱,你也必须站起来!\n")
print("英雄价格:3000\n")
print("插播广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
need_pay = num * 3000
print("(温馨提示)请付款:%s" % need_pay)
pay = int(input('请输入付款金额:'))
if pay >= need_pay:
amount = pay - need_pay
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("\t英雄名称:扎克---生化魔人\n")
print("\t英雄价格:3000\n")
print("\t应付付款:%s\n" % need_pay)
print("\t实际付款:%s\n" % pay)
print("\t找零:%s\n\n" % amount)
print("插入广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡 ")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
else:
print('无法支付!')
else:
print('输入错误或库存不足!')
# 5 杰斯 未来守护者 2500 100 武装着睿智与魅力,你的选择没有错
if buy == 5:
num = int(input('请输入购买数量:'))
if num < 100:
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("英雄名称:杰斯---未来守护者\n")
print("英雄描述:武装着睿智与魅力,你的选择没有错!\n")
print("英雄价格:2500\n")
print("插播广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
need_pay = num * 2500
print("(温馨提示)请付款:%s" % need_pay)
pay = int(input('请输入付款金额:'))
if pay >= need_pay:
amount = pay - need_pay
print("\t英雄商城购买英雄\n")
print("英雄购买票据")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n\n")
print("\t英雄名称:杰斯---未来守护者\n")
print("\t英雄价格:2500\n")
print("\t应付付款:%s\n" % need_pay)
print("\t实际付款:%s\n" % pay)
print("\t找零:%s\n\n" % amount)
print("插入广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡 ")
print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
else:
print('无法支付!')
else:
print('输入错误或库存不足!')
elif choice == "3":
sys.exit()
控制台用户登录注册购买英雄案例
最新推荐文章于 2024-10-08 12:37:10 发布