Advertisement
Guest User

A Simple ATM Machine

a guest
Jan 18th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. """
  2. a simple ATM machine.
  3. """
  4.  
  5. import pickle
  6. from sys import exit
  7.  
  8. try:
  9.     accounts = pickle.load(open('accounts.p', 'rb'))
  10. except IOError:
  11.     accounts = {}
  12.  
  13.  
  14. def UserFound(user):
  15.     if user in accounts:
  16.         return True
  17.     else:
  18.         return False
  19.  
  20. def CreateAccount(user):
  21.     accounts[user] = 0
  22.  
  23. def Withdraw(user, balance):
  24.     try:
  25.         accounts[user] -= balance
  26.     except TypeError:
  27.         print '{} is not a possible value.'.format(balance)
  28.  
  29. def Deposit(user, balance):
  30.     try:
  31.         accounts[user] += balance
  32.     except TypeError:
  33.         print '{} is not a possible value.'.format(balance)
  34.  
  35. def GetBalance():
  36.     print 'Your balance is: {}'.format(accounts[user])
  37.  
  38.  
  39. user = raw_input('What is your full name?\n')
  40.  
  41.  
  42. def MainMenu():
  43.     global user
  44.     print "Welcome {}! What do you want to do?\n1 - Create Account".format(user)
  45.     print "2 - Withdraw Money\n3 - Deposit Money\n4 - See Balance\n5 - Exit\n"
  46.     choice = int(raw_input())
  47.     if choice == 1:
  48.         user = raw_input('What is your full name?\n')
  49.         CreateAccount(user)
  50.         MainMenu()
  51.     elif choice == 2:
  52.         if UserFound(user):
  53.             amount = raw_input('Enter the withdraw amount.')
  54.             Withdraw(user, amount)
  55.             GetBalance()
  56.             MainMenu()
  57.         else:
  58.             print 'User not found.'
  59.             MainMenu()
  60.     elif choice == 3:
  61.         if UserFound(user):
  62.             amount = raw_input('Enter the deposit amount.')
  63.             Deposit(user, amount)
  64.             GetBalance()
  65.             MainMenu()
  66.         else:
  67.             print 'User not found.'
  68.             MainMenu()
  69.     elif choice == 4:
  70.         GetBalance()
  71.         MainMenu()
  72.     elif choice == 5:
  73.         pickle.dump(accounts, open('accounts.p','wb'))
  74.         exit()
  75.  
  76. MainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement