Write a program that simulates an Automatic Teller Machine (ATM). Each user will
ID: 3852595 • Letter: W
Question
Write a program that simulates an Automatic Teller Machine (ATM). Each user will have access to only a checking account. Design your interface to be similar to what you see on your local ATM. Requirements: write Python class to solve this problem: use the basic principles of constructing classes discussed in class. Figure out your nouns, verbs, and the properties of your problem. Since debit card swiping is not possible here, instead ask the user of your program for user id and a PIN. The user id will be used to look up the info for the user's accounts (including the PIN to see if it matches what the user types). You can program some fake accounts and holders directly into your program, with starting balances, i.e. "Sam Johnson" has user sjohnson and a balance of 2310 US dollars. You can program in any number of users you need. The user should able to check the balance of, withdraw from or deposit into their checking account. You can add other actions of your own, as well in addition to the require ones. You should have a main () function that uses any classes you wrote in some sort of interactive loop. The rest is all freestyle.Explanation / Answer
import pickle
import sys
import os
class ATM(object):
def __init__(self):
self.users = [{'id':'sjohnson','name':'San JohnSon','pin':'1233','balance':789},
{'id':'amir','name':'Amir','pin':'2342','balance':90},
{'id':'neo','name':'Neo','pin':'0097','balance':999}]
def check(self,ids):
print "Your balance: "+str(ids['balance'])
def withdraw(self, person):
for i in self.users:
if i['id'] == person['id']:
print "Your balance: "+str(i['balance'])
amount = int(raw_input("Your withdraw amount"))
if amount > i['balance'] or amount < 0:
print "Can't withdraw more than this"+str(i['balance'])
else:
i['balance'] = i['balance']-amount
print "Your balance is: "+str(i['balance'])
def deposit(self,person):
for i in self.users:
if i['id'] == person['id']:
print "Your balance: "+str(i['balance'])
amount = int(raw_input("Your deposit amount"))
if amount > 99999 or amount < 0:
print "Can't deposit more than this"
else:
i['balance'] = i['balance']+amount
print "Your balance is: "+str(i['balance'])
def authentic(self, ids):
flag = 0
for person in self.users:
if person['id'] == ids:
value = person
print "Hello" + str(person['name'])
flag = 1
break
pin = raw_input("Enter your pin: ")
if value['pin'] == pin:
return True, value
def main():
id = raw_input("Enter your id")
a = ATM()
auth, person = a.authentic(id)
if auth:
choice = 0
while choice == 0:
choice = int(raw_input("Select 1 for Check balance; 2 to WithDraw Money; 3 for Deposit Money;4 for exit: "))
if choice == 1:
a.check(person)
choice = 0
if choice == 2:
a.withdraw(person)
choice = 0
if choice == 3:
a.deposit(person)
choice = 0
if choice == 4:
sys.exit(0)
else:
print "Not valid user"
sys.exit(0)
if __name__=="__main__":
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.