其他分享
首页 > 其他分享> > ATM系统和购物车系统

ATM系统和购物车系统

作者:互联网

目录

ATM系统

#coding=utf8
#Version:python 3.6.4
#Tools:Python 2019.9.7
_data_ = '2019/9/7/016 15:27'  #时间
_author_ ='gaofeng'     #作者


'''
ATM机
需求:
1.登陆
    输入账号输入密码
    每日只有3次登陆密码错误的机会,超过3次禁止登陆
2.查询余额
3.存款
4.取款
5.转帐
6.退出
'''
infos = [
    {'name': 'gaofeng', 'pwd': '123', 'yue': 0},
    {'name': 'chenggc', 'pwd': '123', 'yue': 0},
    {'name': 'jinyuy', 'pwd': '123', 'yue': 0},
]

# 禁止登陆
ban = False
# 登陆状态
login_state = False
# 账号密码错误次数
login_num = 0
# 菜单 choice
choice = 0
# 输入的用户名
name = ''
# 输入的密码
pwd = ''
# 余额
yue = 0

while ban == False:
    # 登陆
    while login_state == False:
        # 登陆
        name = input('请输入账号:')
        pwd = input('请输入密码:')

        # 查询账号密码是否正确
        for info in infos:
            if name == info['name'] and pwd == info['pwd']:
                print('登陆成功!')
                login_state = True
                yue = info['yue']
                break
        # 如果没有账号密码不正确则 运行下面的代码
        if login_state == False:
            login_num += 1
            print('账号密码错误!请重新输入!剩余次数 %s' % (3 - login_num))
            if login_num == 3:
                print('今日登陆错误次数超限,请明日再来')
                ban = True
                break
    # 打印菜单
    if login_state == True and choice == 0:
        print('''
        1 查询
        2 存款
        3 转帐
        4 取款
        5 退出
        ''')
        choice = int(input('请输入操作状态:'))

    # 查询
    if login_state == True and choice == 1:
        print('%s 账户的余额为 %s ¥' % (name, yue))
        choice = 0

    # 存款
    if login_state == True and choice == 2:
        money = int(input('请输入你的金额:'))
        for info in infos:
            if name == info['name']:
                info['yue'] += money
                yue += money
                print('%s 账户存入 %s ¥' % (name, money))
        choice = 0
    # 转帐:
    if login_state == True and choice == 3:
        to_state = 0  # 1:成功 2:余额不足
        to_num = 0
        while to_state == 0:
            to_name = input('请输入转入的用户名:')
            # 判断 用户是否存在
            for info in infos:
                if to_name == info['name']:
                    money = int(input('请输入转帐的金额:'))
                    # 判断自己账户的金额是否足够
                    if yue >= money:
                        info['yue'] += money
                        yue -= money
                        print('你给 %s 用户成功转入 %s ¥' % (to_name, money))
                        to_state = 1
                        break
                    else:
                        print('你的余额不足,请充值后再转帐')
                        to_state = 2
            if to_state == 1:
                break
            elif to_state == 2:
                break
            else:
                to_num += 1
                print('你输入的用户不存在,请重新输入:')
        choice = 0

    # 取款
    if login_state == True and choice == 4:
        money = int(input('请输入你的取款金额:'))
        # 判断输入的金额是否小于等于余额
        if money <= yue:
            print('请再出钞口取钞票吧!')
            yue -= money
            choice = 0
        else:
            print('你输入的金额大于你的余额,无法取款!')

    # 退出
    if login_state == True and choice == 5:
        break

购物车系统

#coding=utf8
#Version:python 3.6.4
#Tools:Python 2019.9.7
_data_ = '2019/9/7/016 15:27'  #时间
_author_ ='gaofeng'     #作者

salary = int(input("请输入你的工资:"))
shoppingmart = []
items = (["1","huawei","¥",6799],["2","earphone","¥",3000],["3","notebook","¥",8000])
msg_items = """
--------items-------
1.huawei  $  6799
2.earphone  $  3000 
3.notebook  $  8000
-------------------

"""
print(msg_items)
while True:
    shopindex = int(input("选择商品:"))
    if salary > items[shopindex-1][3]:
        shoppingmart.append(items[shopindex-1])
        salary -=int(items[shopindex-1][3])
        print("你已经买了 {name}!".format(name=items[shopindex-1][1]))
        print("你的余额是:$",salary)
        decision =input("你现在想离开吗?")
        print(msg_items)
    else:
        print("你的余额不够!请试试别的.")
        recharge_ans = input("你想充值码?")
        if recharge_ans =="y":
            recharge = int(input("请输入金额:"))
            print("请等一会...")
            salary +=recharge
            print("你充值成功了!")
            print("余额是:",salary,"现在!")
        decision =input("你现在想离开吗?")
        print(msg_items)
    if decision == "q":
        break
    else:
        continue
print("你已经买了:",shoppingmart)
print("你的余额:$,salary")
print("欢迎你下次光临!")

标签:name,ATM,系统,购物车,state,print,input,login,yue
来源: https://www.cnblogs.com/gfhh/p/11481240.html