Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- a simple ATM machine.
- """
- import pickle
- from sys import exit
- try:
- accounts = pickle.load(open('accounts.p', 'rb'))
- except IOError:
- accounts = {}
- def UserFound(user):
- if user in accounts:
- return True
- else:
- return False
- def CreateAccount(user):
- accounts[user] = 0
- def Withdraw(user, balance):
- try:
- accounts[user] -= balance
- except TypeError:
- print '{} is not a possible value.'.format(balance)
- def Deposit(user, balance):
- try:
- accounts[user] += balance
- except TypeError:
- print '{} is not a possible value.'.format(balance)
- def GetBalance():
- print 'Your balance is: {}'.format(accounts[user])
- user = raw_input('What is your full name?\n')
- def MainMenu():
- global user
- print "Welcome {}! What do you want to do?\n1 - Create Account".format(user)
- print "2 - Withdraw Money\n3 - Deposit Money\n4 - See Balance\n5 - Exit\n"
- choice = int(raw_input())
- if choice == 1:
- user = raw_input('What is your full name?\n')
- CreateAccount(user)
- MainMenu()
- elif choice == 2:
- if UserFound(user):
- amount = raw_input('Enter the withdraw amount.')
- Withdraw(user, amount)
- GetBalance()
- MainMenu()
- else:
- print 'User not found.'
- MainMenu()
- elif choice == 3:
- if UserFound(user):
- amount = raw_input('Enter the deposit amount.')
- Deposit(user, amount)
- GetBalance()
- MainMenu()
- else:
- print 'User not found.'
- MainMenu()
- elif choice == 4:
- GetBalance()
- MainMenu()
- elif choice == 5:
- pickle.dump(accounts, open('accounts.p','wb'))
- exit()
- MainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement