title: In python, how do I update the balance when I withdraw money then deposit money?
body: <p>I am creating an ATM using python code, and I need to create deposit and withdraw functions that behave just like an ATM would. Separately, the deposit and withdraw functions work. However, when I withdraw first then deposit, the balance does not update. Same thing when I deposit then withdraw. </p>
  
  <p>Thank you and your help is much appreciated.</p>
  
  <pre><code>balance = 600
  
  def withdraw():  # asks for withdrawal amount, withdraws amount from balance, returns the balance amount
      counter = 0
      while counter &lt;= 2:
          while counter == 0:
              withdraw = int(input("Enter the amount you want to withdraw: AED "))
              counter = counter + 1
          while ((int(balance) - int(withdraw)) &lt; 0):
              print("Error Amount not available in card.")
              withdraw = int(input("Please enter the amount you want to withdraw again: AED "))
              continue
          while ((float(balance) - float(withdraw)) &gt;= 0):
              print("Amount left in your account: AED" + str(balance - withdraw))
              return (balance - withdraw)
          counter = counter + 1
  
  
  def deposit():
      counter = 0
      while counter &lt;= 2:
          while counter == 0:
              deposit = int(input("Enter amount to be deposited: "))
              counter = counter + 1
          while ((int(balance) + int(deposit)) &gt;= 0):
              print("Amount left in your account: AED" + str(balance + deposit))
              return (balance + deposit)
          counter = counter + 1
  
  withdraw()
  deposit()
  </code></pre>
  
  <hr>
  
  <p>If I withdraw 17, the balance will be 583. However, when I deposit 12, the balance becomes 612, which is wrong it should be 595.</p>