利用Python编程实现ATM机,可以实现查看余额,存钱,取钱三个功能。
money = 5000000
name = input("请输入您的姓名:")
# 主菜单
def main_menu():
print("---------主菜单----------")
print(f"{name},您好,欢迎使用ATM机,请选择操作")
print("查询余额 [输入1]")
print("存款 [输入2]")
print("取款 [输入3]")
print("退出 [输入4]")
global i
i = int(input("请输入您的选择:"))
# 查询余额
def inquire():
print("----------查询余额---------")
print(f"{name},您好,您的余额剩余:{money}元")
# 存款
def deposit():
print("请输入您要存的金额:")
dep = int(input())
global money
money = money+ dep
print("-----------存款------------")
print(f"{name},您好,你存款{dep}元,成功\n{name},您好,您的余额剩余:{money}元")
# 取款
def withdrawal():
print("请输入您要取的金额:")
wit = int(input())
global money
if wit <= money:
money = money - wit
print("-----------取款------------")
print(f"{name},您好,你取款{wit}元,成功\n{name},您好,您的余额剩余:{money}元")
else:
print("余额不足!!!")
# 调用
main_menu()
for i in range(1,5):
if i == 1:
inquire()
main_menu()
continue
elif i == 2:
deposit()
main_menu()
continue
elif i == 3:
withdrawal()
main_menu()
continue
else:
print("感谢您的使用")
实现结果展示