day3 ATM机加购物车

run_case

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from day04.day4.Atm import ATM
from day04.day4.shopping import shoppin
from day04.day4.admin import admin_view
def run_case():
    run={"1":ATM,"2":shoppin,"3":admin_view}
    while True:
        r = '''
                 "1":ATM功能
                 "2":购物功能
                 "3":admin功能
                 
           '''
        print(r)
        index = input("请输入要使用功能的,/n退出")
        if index=="n":
            return
        if index in run:
            run[index]()
        else:
            print("输入错误")
run_case()

  ATM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import os
import time,random
 
def aout(func):
    def wrepper(*args,**kwargs):
        login_user = input("bank_account:").strip()
        login_paw = input("bank_paw").strip()
        with open("register.txt", mode='rt', encoding="utf-8") as login:
            for line in login.readlines():
                line = line.strip('\n').split(',')
                if login_user == line[0] and login_paw == line[1]:
                    ret = func(*args, **kwargs)
                    return ret
                elif line[2]=="1":
                    print("账号已冻结")
                    return
            else:
                print("密码错误,请从新输入...")
    return wrepper
def Log(func):
    def wrepper(*args,**kwargs):
        ret = func(*args, **kwargs)
        func_name=func.__name__
        tims= time.strftime('%Y-%m-%d %X')
        with open("access.log",mode="a",encoding="utf-8")as w:
                a = "当时时间%s执行函数%s当前记录%s" % (tims, func_name, ret)
                w.write(a+'\n')
                return ret
    return wrepper
def register():
    # 注册
    user=input("请输入注册用户:")
    pwd=input("请输入注册密码:")
    status="0"
    with open("register.txt",mode="at",encoding="utf-8")as regit:
        regit.write(user+','+pwd+","+status)
        print("注册成功,前去登录吧")
        return
@aout
def ATM_login():
    # 登录
    print("登录成功")
@aout
@Log
def credit():
    """申请信用卡 """
    with open("register.txt", mode="r", encoding="utf-8")as r:
        for i in r.readlines():
            line=i.strip().split(',')
            print(line[0])
            user=input("user:")
            if user in line[0]:
                cret = '''
                    请选择您要申请的信用卡类型,
                    1:  可用额度15000,
                    2:  自定义额度
                    '''
                print(cret)
            credit_type = input("请选择...")
            with open("credit_money.txt", mode="a", encoding="utf-8")as credit:
                if credit_type == "1":
                    money=15000
                    data={"user":user,"money":money,"rfund":None}
                    credit.write(data)
                    print("恭喜您申请信用卡成功\n,信用额度为15000")
                    return user,money
                elif credit_type == "2":
                    money = input("请输入您要申请的额度")
                    data={"user":user,"money":money,"rfund":None}
                    credit.write(data)
                    print("您的额度已成功申请到您的账户")
                    return user,money
                else:
                    print("请从新选择...")
        else:
            print("请从新输入您的账号")
@aout
@Log
def carry_money():
    user = input("请输入您的账号")
    with open("credit_money.txt",mode="r",encoding="utf-8")as carry,\
            open("new_credit_money.txt", mode="a", encoding="utf-8")as a:
        carry=carry.read()
        line=eval(carry)
        if  user == line["user"]:   #如果用户在信用卡用户里面
            CarryMoney = int(input("请输入要提现的金额"))
            if CarryMoney+(CarryMoney*0.05)> line["money"]:
                 print("提现金额超出信用卡可提额度")
            else:
                 new_money= int(line["money"]) - (CarryMoney + (CarryMoney * 0.05))
                 rfund=CarryMoney + (CarryMoney * 0.05)
                 data = {"user": user, "money": new_money, "rfund": rfund}
                 a.write(data)
                 return data
        else:
            print("用户账号不存在")
    os.remove("credit_money.txt")
    os.rename("new_credit_money.txt", "credit_money.txt")
@aout
@Log
def transfer():
    # 转账
    account = input("请输入您的账号:")
    transfer_user = input("请输入要转账的账号")
    with open("credit_money.txt", mode="r", encoding="utf-8")as transfer,\
    open("new_credit_money.txt",mode="at",encoding="utf-8")as transfer1:
        for line in transfer1:
            line = eval(line)
            if account ==line["user"]:
                money = int(input("请输入要转账的金额"))
                if money <=line["money"]:
                    transfer_money=line["money"]-money
                    # 转账另存
                    transfer.write(transfer_user+','+transfer_money)
                    return account,transfer_money
                else:
                    print("输入金额大于余额,请从新输入")
            else:
                 print("账号不存在")
    os.remove("credit_money.txt")
    os.rename("new_credit_money.txt", "credit_money.txt")
 
@aout
@Log
def refund():
    user=input("请输入要还款的账号:")
    with open("credit_money.txt", mode="r", encoding="utf-8")as refund,\
    open("new_credit_money.txt", mode="at", encoding="utf-8") as a:
        refud=refund.read()
        refud=eval(refud)
        if user in refud["user"]:
            refund_money=int(input("请输入要还款的金额:"))
            if refund_money >refud["refund"]:
                print("输入金额超出返款金额")
            else:
                new_refund=refud["refund"]-refund_money
                money_refund=new_refund+refund["money"]
                data = {"user": user, "money": money_refund, "rfund": new_refund}
                a.write(data)
                return user,data
    os.remove("credit_money.txt")
    os.rename("new_credit_money.txt","credit_money.txt")
@aout
@Log
def bill():
   '''每月22号出账单,每月10号为还款日,过期未还,按欠款总额万分之5每日计息'''
   with open("credit_money.txt", mode="r", encoding="utf-8")as r_bill:
       r_bill = r_bill.read()
       r_bill = eval(r_bill)
       user=input("user")
       if user in r_bill["user"]:
           if r_bill["rfund"] !=0:
               t = time.strftime("%d")
               ti=22
               tm=10
               with open("bill_detill.txt",mode="at",encoding="utf-8")as a:
                   if int(t)>tm:
                       newt=int(time.strftime("%d")) - int(t)
                       new_bill=int(r_bill["rfund"])*0.05*newt
                       if time.strftime("%d")==ti:
                           b="用户%s,的账单为%s,需要还款金额为%s"%(user,r_bill["rfund"],new_bill)
                           a.write(time.strftime("%Y-%m-%d %X")+','+b+'\n')
                           return user,b
 
def ATM():
    # if not ATM_login():
    #     return
    se={"3":carry_money,"4":transfer,"5":bill,"6":credit,"7":refund}
    while True:
        atm = '''
                 "3":提现
                 "4":转账
                 "5":出账单
                 "6":申请信用卡
                 "7":还款
           '''
        print(atm)
        index = input("请输入要使用功能的,/n退出")
        if index=="n":
            return
        if index in se:
            se[index]()
        else:
            print("输入错误")
 
 
if __name__ == '__main__':
    ATM()

  shopping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
from day04.day4.Atm import ATM_login
# 购物中心========================================
# 商品信息
products = [{"name":"挨粪叉","price":6888},
            {"name":"锤子TNT","price":10888},
            {"name":"小米mix2","price":2888}]
 
# 购物车
car = {}
# 购物
def shopping():
    while True:
    # 打印出所有商品信息
        count=1
        for i in  products:
            print(f"序号",{count},"商品",{i["name"]},"价格",{i["price"]})
            count+=1
        select=input("请选择要添加的商品序号  ,按n退出")
        if select=="n":
            return
        if select.isdigit() and int(select) >=1 and int(select) <= len(products):
            idex=products[int(select)-1]
            print("购物商品已添加成功%s"%idex["name"])
            if idex["name"] in car:
                car[idex["name"]]["count"]+=1
            else:
                car[idex["name"]]={"price":idex["price"],"count":1}
        else:
            print("输入有误  请从新输入")
def show_goods():
    if not car:
        s=input("您的购物车是空的,输入y/n")
        if s=="y":
            shopping()
            return
        else:
            return
    print("您的购物车信息:")
    for name in car:
        print("名称:%-10s 价格:%-8s 数量:%-3s 总价:%-10s" % (name,
                                                     car[name]["price"],
                                                     car[name]["count"],
                                                     car[name]["price"] * car[name]["count"]))
        select = input("输入y调整商品数量!(数量为0则删除商品!)(数量为1则购买商品!) 输入其他退出!")
        if select == "y":
            modify_count()
def modify_count():
    name=input("请输入商品名称,q则退出")
    while True:
        if name=="q":
            return
        if name not in car:
            continue
    while True:
        count=int(input("请输入数量:"))
        if count==0:
            car.pop(name)
            print("%s已删除"%name)
        else:
            car[name]["count"]=count
            print("数量更改成功")
            return
def pay():
    sum=0
    for name in car:
        sum+=car[name]["price"] * car[name]["count"]
    user = input("请输入您的账号")
    with open("credit_money.txt", mode="r", encoding="utf-8")as carry, \
            open("new_credit_money.txt", mode="a", encoding="utf-8")as a:
        carry = carry.read()
        line = eval(carry)
        if user == line["user"]:  # 如果用户在信用卡用户里面
            if sum>line["money"]:
                print("额度不足。。")
            else:
                money=line["money"]-sum
                mo=line.replace(["money"],money)
                a.write(mo)
    os.remove("credit_money.txt")
    os.rename("new_credit_money.tx","credit_money.txt")
 
 
 
def  shoppin():
     # if not ATM_login():
     #     return
     while True:
        numbr='''
              "1":购物,
              "2":查看购物车,
              "3":修改购物车商品,
              "4":结算
         
         
        '''
        print(numbr)
        index=input("请输入要使用功能的序号")
        goods={"1":shopping,"2":show_goods,"3":modify_count,"4":pay}
        if index in goods:
 
            goods[index]()
        else:
            print("请从新输入")
if __name__ == '__main__':
    shoppin()

  admin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import time
from day04.day4.Atm import ATM_login
def admin_add_user():
    user=input("请输入要添加的用户:")
    with open("register.txt", mode='rt', encoding="utf-8") as add_user,\
    open("register.txt", mode='at', encoding="utf-8")as writ:
        for line in add_user.readlines():
            line = line.strip('\n').split(',')
            if user == line[0]:
                print("用户已存在")
            else:
                pwd=input("请输入您的密码")
                writ.write(user+','+pwd+'\n')
                print("添加用户成功")
 
def  lock_user():
    user=input("请输入要冻结的账号:")
    with open("register.txt", mode='rt', encoding="utf-8") as lock_r,\
            open("new_register.txt", mode='at', encoding="utf-8")as lock_w:
        for line in lock_r.readlines():
            line = line.strip('\n').split(',')
        if user == line[0]:
            lock_w.write(str(line).replace(line[2],"1"))
        else:
            print("user不正确")
    os.remove("register.txt")
    os.rename("new_register.txt","register.txt")
def  unlock_user():
    user=input("请输入要冻结的账号:")
    with open("register.txt", mode='rt', encoding="utf-8") as lock_r,\
            open("new_register.txt", mode='at', encoding="utf-8")as lock_w:
        for line in lock_r.readlines():
            line = line.strip('\n').split(',')
        if user == line[0]:
            lock_w.write(str(line).replace(line[2],"0"))
        else:
            print("user不正确")
    os.remove("register.txt")
    os.rename("new_register.txt","register.txt")
def adjust_quota():
    adjust=input("请输入要调整额度的用户")
    with open("credit_money.txt", mode="rt", encoding="utf-8")as r,\
    open("new_credit_money.txt", mode="rt", encoding="utf-8")as w:
        for i in r.readlines():
            if  adjust==i[0]:
                us=input("请输入新的额度")
                i=i.replace(i[1],us)
                w.write(i)
    os.remove("credit_money.txt")
    os.rename("new_credit_money.txt","credit_money.txt")
def admin_view():
    # 调用登录功能验证是否有权限执行操作
    # if not ATM_login():
    #     return
    admin_funcs = {"1":admin_add_user,"2":lock_user,"3":adjust_quota,"4":unlock_user}
    while True:
        print("""
1.添加账户
2.修改额度
3.冻结账户
4.解冻账户
(q.退出!)""")
        index = input("请选择:\n")
        if index == "q":
            return
        if index in admin_funcs:
            admin_funcs[index]()
        else:
            print("输入有误请重试!")
if __name__ == '__main__':
    admin_view()

  

posted @   小林子哈哈  阅读(100)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示