title: ATM Program Python
body: <p>I submitted this code for a simple ATM program in python. I got full credit but was told not to use global variables as they are considered bad programming. I've tried rewriting this function a million times, but when I do my balance isn't updating. Can someone show me what I'm doing wrong? It's bothering me that I can't figure it out myself!</p>
  
  <p>My original:</p>
  
  <pre><code>name=input("Name on your bank account? ")
  balance=float(input("Your current balance? "))
  
  def printMenu():
      print(name,"Welcome to the Lots of Money Bank")
      print("Enter 'b'(balance), 'd'(deposit), 'w'(withdraw), or'q'(quit)")
  
  def getTransaction():
      transaction=str(input("What would you like to do? "))
      return transaction
  
  def withdraw(bal,amt):
      global balance
      balance=bal-amt
      if balance&lt;0:
          balance=balance-10
  
  def formatCurrency(amt):
      return "$%.2f" %amt
  
  ###MAIN PROGRAM###
  
  printMenu()
  command=str(getTransaction())
  
  while command!="q":
      if (command=="b"):
          print(name,"Your current balance is",formatCurrency(balance))
          printMenu()
          command=str(getTransaction())
      elif (command=="d"):
          amount=float(input("Amount to deposit? "))
          balance=balance+amount
          printMenu()
          command=str(getTransaction())
      elif (command=="w"):
          amount=float(input("Amount to withdraw? "))
          withdraw(balance,amount)
          printMenu()
          command=str(getTransaction())
      else:
          print("Incorrect command. Please try again.")
          printMenu()
          command=str(getTransaction())
  
  print(name,"Goodbye! See you again soon")
  </code></pre>
  
  <p>My edited withdraw function:</p>
  
  <pre><code>def withdraw(bal,amt):
      bal=balance
      amt=amount
      if(bal&lt;0):
          bal=bal-10
      else:
          bal=bal-amt
      return bal
  
  and my edited elif
  elif (command=="w"):
          amount=float(input("Amount to withdraw? "))
          withdraw(balance,amount)
          printMenu()
          command=str(getTransaction())
  </code></pre>