需求描述:
期望输出效果:
练习成果:
#简单的银行业务流程
many = 50000
def main_menu():
print("----------主菜单----------"
f"\n{name}您好,欢迎来到ATM,请选择操作:"
"\n查询余额\t[输入1]"
"\n存款\t\t[输入2]"
"\n取款\t\t[输入3]"
"\n退出\t\t[输入4]")
return input("请输入您的选择:")
def check(show_header):
'''查询账户当前余额'''
if show_header:#通过参数控制内容的输出
print("----------查询---------")
print(f"您好,查询到您的当前余额为:{many}元")
def deposit(num):
'''存入账户金额并查询存入后的余额'''
global many
many = int(num) + int(many)
print (f"您好,您存款{num}元成功,当前余额为:{many}元")
check(False)
def withdrow(num1):
'''取出账户金额并查询存入后的余额'''
global many
many = int(many) - int(num1)
print(f"您好,您取款{num1}元成功,当前余额为:{many}元")
check(False)
name = input("请输入您的姓名:")
while True:
keyboard_input = main_menu()
if keyboard_input == "1":
check(True)
continue
elif keyboard_input == "2":
num = input("请输入您需要存入的金额:")
deposit(num)
continue
elif keyboard_input == "3":
num1 = input("请输入您需要取出的金额:")
withdrow(num1)
continue
else:
print("退出程序")
break