python小项目--》ATM机系统

"""
1.登录
2.存款
3.取款
4.改密
5.查询
6.转账
7.退出
"""
class ATM007:
    def __init__(self):
        self.login_flag = False
        self.totle_money = 0
        self.password = "135531"

    # 存款的功能
    def cun_kuan(self):
        print("请输入存款金额:")
        money = input()
        if money.isdigit():
            money = int(money)
            self.totle_money += money
            print("存款成功,剩余金额%d" % self.totle_money)
        else:
            print("您存入的是假币,你先在这里等着,我去找警察")
            return

    # 取款的功能
    def qu_kuan(self):
        print("请输入取款金额:")
        money = input()
        if money.isdigit():
            money = int(money)
            if self.totle_money >= money:
                self.totle_money -= money
                print("取款成功,剩余金额%d" % self.totle_money)
            else:
                print("您的余额不足,请先存入,再取出")
                return

    # 改密的功能
    def gai_mi(self):
        print("请输入新密码:")
        userpwd = input()
        print("请再次输入新密码:")
        reuserpwd = input()
        if userpwd == reuserpwd:
            if (len(userpwd) == 6) and (userpwd.isdigit()):
                self.password = userpwd
                print("修改密码成功")
                self.login_flag = False
            else:
                print("密码应该是6位数字")
        else:
            print("两次输入密码不一致")

    # 查询余额
    def cha_xun(self):
        print("您的余额为%d" % self.totle_money)
        return self.totle_money

    # 转账功能
    def zhuan_zhang(self):
        print("请输入转账卡号:")
        mu_biao = input()
        if ((len(mu_biao) == 16) or (len(mu_biao) == 19)) and mu_biao.isdigit():
            print("请输入转账金额:")
            money = input()
            if money.isdigit():
                money = int(money)
                if self.totle_money >= money:
                    self.totle_money -= money
                    print("转账成功,剩余金额%d" % self.totle_money)
                else:
                    print("您的余额不足,请先存入,再转出")
                    return
        else:
            print("输入帐号错误")
            return

        # 创建对象


ATM = ATM007()
print("欢迎使用火星银行ATM自动柜员机:")
print("请插入您的IC卡:")
while True:
    if not ATM.login_flag:
        count = 3
        while count > 0:
            print("请输入密码:")
            password = input()
            if password == ATM.password:
                print("登陆成功")
                ATM.login_flag = True
                break
            else:
                count -= 1
                print("登陆失败,还剩下%d次机会" % count)
    else:
        print("请选择您需要的服务:1.存款    2.取款    3.改密    4.查询    5.转账    6.退出")
        select = int(input())
        if select == 1:
            # 存款的功能
            ATM.cun_kuan()
        elif select == 2:
            # 取款的功能
            ATM.qu_kuan()
        elif select == 3:
            # 改密的功能
            ATM.gai_mi()
        elif select == 4:
            # 查询功能
            ATM.cha_xun()
        elif select == 5:
            # 取款的功能
            ATM.zhuan_zhang()
        elif select == 6:
            print("欢迎下次光临")
            break
        else:
            print("您选择的服务我们无法提供,请到隔壁店里去")


2. 模拟银行账户业务,实现存款、取款和余额查询。运行效果如下所示:
1.存款  2.取款  3.查询  0.退出
请选择你要办理的业务:1
请输入存款金额:1000
---------
存款成功!

1.存款  2.取款  3.查询  0.退出
请选择你要办理的业务:2
请输入取款金额:100
---------
取款成功!

1.存款  2.取款  3.查询  0.退出
请选择你要办理的业务:
---您当前账户余额:900元---

1.存款  2.取款  3.查询  0.退出
请选择你要办理的业务:0

O(∩_∩)O谢谢您的使用,欢迎下次光临!

"""
total_money = 0

# 存钱的方法
def save_money(money, total_money):
    total_money += money
    return total_money

# 取钱的方法
def get_money(money, total_money):
    total_money -= money
    return total_money

while True:
    select = input("1.存款  2.取款  3.查询  0.退出\n请选择你要办理的业务:")
    if select == "1":
        money = int(input("请输入存款金额:"))
        total_money = save_money(money, total_money)
    elif select == "2":
        money = int(input("请输入取款金额:"))
        total_money = get_money(money, total_money)
    elif select == "3":
        pass
    elif select == "0":
        print("欢迎下次光临,再见")
        break
    else:
        print("您的输入有误")
    print("您的余e还剩下:%d" % total_money)

猜你喜欢

转载自blog.csdn.net/qq_42336700/article/details/81411335