黑馬程序員python教程,8天python從入門到精通,學python看這套就

# 方法二:通過循環(huán)語句來無限循環(huán)
# 定義查詢函數(shù)
def query(show):
if show:
print("----------查詢余額----------")
print(f"{name},您好!您的余額為{money}元")
# 定義存款函數(shù)
def save_money(num):
global money
print("-----------存款-----------")
print(f"{name},您好!您存款為{num}元成功")
money = money + num
query(False)
# 定義取款函數(shù)
def take_money(num):
global money
print("-----------取款-----------")
if num <= money:
money = money - num
print(f"{name},您好!您取款{num}元成功")
query(False)
else:
print(f"{name},您好!您的余額為{money}元,取款失敗")
# 定義主菜單函數(shù)
def menu():
print("-------------------主菜單-------------------")
print(f"{name},您好!歡迎來到XX銀行,請選擇您要辦理的業(yè)務")
print("查詢余額\t[輸入1]")
print("存款\t\t[輸入2]")
print("取款\t\t[輸入3]")
print("退出系統(tǒng)\t[輸入4]")
return input("")
# 設(shè)置無限循環(huán)
while True:
i = menu()
if i == "1":
query(True)
elif i == "2":
num = int(input("你想存多少錢:"))
save_money(num)
elif i == "3":
num = int(input("你取存多少錢:"))
take_money(num)
elif i == "4":
break
else:
print("請輸入正確的數(shù)字")