In: Computer Science
Due Sept 25th at 11:55 pm
You are going to make an advanced ATM program
When you run the program, it will ask you if you want to:
Either log in or make a new user
Exit
Once I have logged in, I will have 3 balances, credit, checking, and savings. From here it will ask which account to use.
Once the account is picked they can deposit, withdraw, check balance, or log out.
Each time the user performs one of these actions, it will loop back and ask them for another action, until the Logout
(Hint: Make sure they can’t withdraw too much money)
Submission name: Advanced_ATM.py
(Capitalization matters for this, any non .py files will be -20 points)
Submit the file here by the assigned date, every day late will be 15 points off
The following code performs the tasks specified in the question:
#list of users
users = []
currUser = None
#userclass
class User:
def __init__(self,uname,pwd): #constructor
self.username = uname
self.password = pwd
self.accounts = {"credit" : 0, "checking" : 0, "savings" : 0}
def auth(self,uname,pwd): #authentication function
return self.username == uname and self.password == pwd
def login(uname,pwd): #method for login
for user in users:
if(user.auth(uname,pwd)):
return (True, user)
else:
return False
def checkUserName(uname): #makes sure usernames are unique
for user in users:
if user.username == uname:
return False
return True
def newUser(): #creates a new user
uname = ""
while True:
uname = str(raw_input("Enter your username :\t"))
if checkUserName(uname) == False:
print("Username {} has already been taken".format(uname))
else:
break
pwd = str(raw_input("Enter your password:\t"))
newUser = User(uname,pwd)
users.append(newUser)
print("User created successfully! Please enter your credentials at
the login page to Sign In.")
menu1()
def menu1(): #login menu
global currUser
while True:
print("\n\n\n*********ATM Menu*********")
print("1. Login")
print("2. New User? Register")
print("3. Exit")
x = int(raw_input("Enter your choice:\t"))
if x == 1:
uname = str(raw_input("Enter your username :\t"))
pwd = str(raw_input("Enter your password:\t"))
#print(uname,pwd)
res = login(uname,pwd)
if isinstance(res,tuple):
currUser = res[1]
menu2()
else:
print("Invalid Username/Password")
elif x == 2:
newUser()
else:
break
def menu2(): #user menu
global currUser
print("\n\n\nWelcome {}".format(currUser.username))
acccode_map = {"ch" : "checking","cr" : "credit", "sv" :
"savings"}
while True:
acc_type = str(raw_input("\nEnter code for the account to query:
Credit (cr) ; Checking (ch) ; Savings (sv):\t"))
if acc_type in acccode_map:
menu3(acccode_map[acc_type])
else:
print("Invalid choice! no such account type
{}".format(acc_type))
back=str(raw_input("DO you want to logout (Y/n)?:\t"))
if back[0:1] == "Y" or back[0:1] == "y":
currUser = None
menu1()
def menu3(acc_type): #account menu
global currUser
max_tranaction = 500 #We cap the transaction at $500
print("\n\n\nSelected Account Type : {}".format(acc_type))
while True:
print("\n*****User Menu*****")
print("1. Check Balance")
print("2. Withdraw Money")
print("3. Deposit Money")
x = int(raw_input("Enter your choice:\t"))
if x == 1:
print ("Balance : {}".format(currUser.accounts[acc_type]))
elif x == 2:
bal = currUser.accounts[acc_type]
amount = int(raw_input("Enter amount:\t"))
if amount > bal:
print("Insufficient Balance! Transaction aborted.")
elif amount > 500:
print("Transactions are capped at a max of $500.")
else:
currUser.accounts[acc_type] = bal - amount;
print("Amount successfully withdrawn")
elif x == 3:
bal = currUser.accounts[acc_type]
amount = int(raw_input("Enter amount:\t"))
currUser.accounts[acc_type] = bal + amount
print("Amount successfully deposited")
back=str(raw_input("Go back to user menu (Y/n)?:\t"))
if back[0:1] == "Y" or back[0:1] == "y":
menu2()
if __name__ == "__main__":
menu1()
Indentation Screenshots:
Output Screenshots: