控制台用户登录注册购买英雄案例(修订版)

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('(温馨提示)请输入您要购买的英雄编号:'))
 
    # 1     纳尔   迷失之牙  3500  100  丛林不会原谅盲目与无知
            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('输入错误或库存不足!')
 
        # 2     锐雯   放逐之刃  4000  100  她是残忍高效的战士
            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('输入错误或库存不足!')
 
        # 3     薇恩   暗夜猎手  3500  100  这个世界不想人们想象的那么美好
            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('输入错误或库存不足!')
 
        # 4     扎克   生化魔人  3000  100  即使你没有脊柱,你也必须站起来
            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()
 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值