如何实现一个while循环来继续取最新的值？

[英]How to implement a while loop to continue taking the latest value?

``````def withdrew(t, w):
if t>w:
balance=int(t-w)
return balance
else:
return ("Not enough money to wthdrew.")

def deposit(d):
current_balance=withdrew(t, w)
new_balance = current_balance + d
return new_balance

t=int(input("What is your total amount: "))

is_game_on= True
while is_game_on:
w=int(input("How much amount you would like to withdrew? "))
withdraw_money=withdrew(t, w)
d = int(input("How much you would like to deposit? "))
deposit_money=deposit(d)
user=input("Would you like to play-'y'or 'n'? ").lower()
if user=='y':
is_game_on=True
else:
is_game_on=False
``````

Output如下：

``````What is your total amount: 100
How much amount you would like to withdrew? 10
How much you would like to deposit? 100
Would you like to play-'y'or 'n'? y
How much amount you would like to withdrew? 10
``````
``````def withdrew(bank, w):
if bank>w:
bank=int(bank-w)
return bank
else:
print("Not enough money to wthdrew.")
return bank

def deposit(bank, d):
return bank + d

t=int(input("What is your total amount: "))
bank = t

is_game_on= True
while is_game_on:
w=int(input("How much amount you would like to withdrew? "))
bank=withdrew(bank, w)
d = int(input("How much you would like to deposit? "))
bank=deposit(bank, d)
user=input("Would you like to play-'y'or 'n'? ").lower()
if user=='y':
is_game_on=True
else:
is_game_on=False
``````

``````def withdraw(t, w):
if t < w:
raise ValueError("You cannot withdraw more money than is in your account.")
return t-w

def deposit(t, d):
return t + d

account_balance = int(input("What is your total amount: "))

while True:
withdraw_amount = int(input("How much amount you would like to withdraw? "))
account_balance = withdraw(account_balance, withdraw_amount)

deposit_amount = int(input("How much you would like to deposit? "))
account_balance = deposit(account_balance, deposit_amount)