money = 500
num2 = 0 #取款金额累计
num3 = 0 #存款金额累计
count = 0 # set 取款次数
name = input("请输入你的名字:")
def left(show_header):
if show_header:
print("------left------")
print(f"您好,{name},您的当前余额为{money}")
def deposit(num):
global money
global num3
# num = int(input("请输入你的存款金额:”))
money += num
num3 += num
if num3 <= 1000: # 此处设置了存款限额
print("------depost------")
print(f"你好{name},你的存款金额为{num},您的累计存款金额为:{num3}")
print(f"您好,{name},您的当前余额为{money}")
else:
print("sorry,everyday you could olny depost 1000 yuan")
def withdraw(num):
global money
global num2
global count
# num2 = int(input("请输入你的取款金额:”))
money -= num
num2 += num
count += 1
print("------withdraw------")
print(f"你好{name},你的本次取款金额为{num},累计取款金额为{num2}")
print(f"您好,{name},您的当前余额为{money}")
print(f"累计取款次数为{count}")
# num += num2
# if num2 > 20000:
# print("sorry,you have been limited,what you withdraw is over 20000")
def main():
print("------main meun------")
print(f"hello {name},welcome to HEIMA ATM")
print("查询余额\t[输入1]")
print("存款\t\t[输入2]")
print("取款\t\t[输入3]")
print("退出\t\t[输入4]")
return input("请输入你的选择:")
while True:
keyboard_input = main()
if int(keyboard_input) == 1: # 学习,从键盘获取的类型为字符串,不可直接使用,两种方法,第一种是将变化为int整形,另外一种是修改为”“如2所示
left(True)
continue
elif keyboard_input == "2":
num = int(input("请输入你想要存入的金额:"))
deposit(num)
continue
elif keyboard_input == "3":
if count <= 4: #限制取款次数不能超过5次
num = int(input("请输入你想要取款的金额:"))
if num <= money:
withdraw(num)
if num2 > 1000: # 此处设置了取款限额,超过1000就超限了
print("sorry,your count is over the limit")
continue
else:
print("sorry,your count is over what you want to withdraw")
else:
print("sorry,your cishu is over the limit")
else:
print("程序退出了")
break
ATM-test
最新推荐文章于 2024-11-13 17:26:18 发布