In: Computer Science
in paython
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
class Account:
def __init__(self,username,password):
self.username = username
self.password = password
self.credit_bal = 0
self.checking_bal = 0
self.savings_bal = 0
def deposit(self,amount,ac_type):
if(ac_type == "credit"):
self.credit_bal
+= amount
print("\nTransaction Success. Successfully deposited in Credit
Account")
elif(ac_type == "checking"):
self.checking_bal += amount
print("\nTransaction Success. Successfully deposited in Checking
Account")
elif(ac_type=="savings"):
self.savings_bal
+= amount
print("\nTransaction Success. Successfully deposited in Savings
Account")
def withdraw(self,amount,ac_type):
if(ac_type == "credit"):
if(self.credit_bal < amount):
print("\nError: Insufficient funds in Credit
Account")
else:
self.credit_bal -= amount
print("\nTransaction Success. Successfully
withdrawed from Credit Account")
elif(ac_type == "checking"):
if(self.checking_bal < amount):
print("\nError: Insufficient funds in Checking
Account")
else:
self.checking_bal -= amount
print("\nTransaction Success. Successfully
withdrawed from Checking Account")
elif(ac_type=="savings"):
if(self.savings_bal < amount):
print("\nError: Insufficient funds in Savings
Account")
else:
self.savings_bal -= amount
print("\nTransaction Success. Successfully
withdrawed from Savings Account")
def check_balance(self,ac_type):
print("\n")
if(ac_type == "credit"):
print("Balance
in Credit account:%.2f" %self.credit_bal)
elif(ac_type == "checking"):
print("Balance
in Checking account:%.2f" %self.checking_bal)
elif(ac_type=="savings"):
print("Balance
in Savings account:%.2f" %self.savings_bal)
def simulate(self):
ac_choice =
get_choice(acc_menu,0,3)
ac_type = ""
if(ac_choice == 0):
print("\nSuccessfully Logged out")
return
elif(ac_choice == 1):
ac_type =
"credit"
elif(ac_choice == 2):
ac_type =
"checking"
elif(ac_choice == 3):
ac_type =
"savings"
op_choice = 1
while(op_choice):
print("\nCurrent
Account Logged in:",ac_type.title())
op_choice =
get_choice(opps_menu,0,3)
if(op_choice ==
0):
print("\nSuccessfully Logged out")
break
elif(op_choice
== 1):
amount = get_amount("\nEnter amount to deposit:
")
self.deposit(amount,ac_type)
elif(op_choice
== 2):
amount = get_amount("\nEnter amount to withdraw:
")
self.withdraw(amount,ac_type)
elif(op_choice
== 3):
self.check_balance(ac_type)
def get_amount(prompt):
is_valid = False
amount = 0
while(not is_valid):
try:
amount =
float(input(prompt).strip())
if(amount
<1):
is_valid = False
print("\nInvalid Amount entered")
else:
is_valid = True
except Exception as e:
print("Invalid
Amount entered")
return amount
def main_menu():
print("\n--------- Main Menu -------------\n")
print("1. Login")
print("2. Register New User")
print("0. Exit")
print("Enter your choice: ",end="")
def acc_menu():
print("\n--------- Select Account Type
-------------\n")
print("1. Credit")
print("2. Checking")
print("3. Savings")
print("0. Log out")
print("Enter your choice: ",end="")
def opps_menu():
print("\n--------- Operations -------------\n")
print("1. Deposit")
print("2. Withdraw")
print("3. Check Balance")
print("0. Log out")
print("Enter your choice: ",end="")
def get_choice(fun,low,high):
is_valid = False
choice = 0
while(not is_valid):
try:
fun()
choice =
int(input().strip())
if(choice <
low or choice > high):
is_valid = False
print("\nInvalid Choice entered")
else:
is_valid = True
except Exception as e:
print("\nInvalid
Choice entered",fun)
return choice
def get_username_and_password():
print("")
username = input("Enter username:
").strip().lower()
if(username == ""):
print("\nError: Empty value for
username is not allowed")
return "",""
password = input("Enter password: ").strip()
if(password == ""):
print("\nError: Empty value for
password is not allowed")
return "",""
return username,password
def main():
users = {}
main_choice = 1
while(main_choice):
main_choice =
get_choice(main_menu,0,2)
if(main_choice == 1):
username,password = get_username_and_password()
if(username !=
"" and password!=""):
if(username in users):
users[username].simulate()
else:
print("\nUser:",username,"not
found in Users array")
elif(main_choice == 2):
username,password = get_username_and_password()
if(username in
users):
print("Duplicate User. Unable to add
user:",username)
else:
users[username] = Account
(username,password)
print("\nSuccessfully created
User:",username)
elif(main_choice == 0):
print("\nQutting.....")
if __name__ == "__main__":
main()
'''
--------- Main Menu -------------
1. Login
2. Register New User
0. Exit
Enter your choice: 2
Enter username: john
Enter password: wick
Successfully created User: john
--------- Main Menu -------------
1. Login
2. Register New User
0. Exit
Enter your choice: 1
Enter username: john
Enter password: wick
--------- Select Account Type -------------
1. Credit
2. Checking
3. Savings
0. Log out
Enter your choice: 1
Current Account Logged in: Credit
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 3
Balance in Credit account:0.00
Current Account Logged in: Credit
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 1
Enter amount to deposit: -100
Invalid Amount entered
Enter amount to deposit: 100
Transaction Success. Successfully deposited in Credit Account
Current Account Logged in: Credit
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 3
Balance in Credit account:100.00
Current Account Logged in: Credit
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 2
Enter amount to withdraw: 200
Error: Insufficient funds in Credit Account
Current Account Logged in: Credit
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 2
Enter amount to withdraw: 50
Transaction Success. Successfully withdrawed from Credit Account
Current Account Logged in: Credit
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 3
Balance in Credit account:50.00
Current Account Logged in: Credit
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 0
Successfully Logged out
--------- Main Menu -------------
1. Login
2. Register New User
0. Exit
Enter your choice: 1
Enter username: john
Enter password: wick
--------- Select Account Type -------------
1. Credit
2. Checking
3. Savings
0. Log out
Enter your choice: 2
Current Account Logged in: Checking
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 3
Balance in Checking account:0.00
Current Account Logged in: Checking
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 1
Enter amount to deposit: 100
Transaction Success. Successfully deposited in Checking Account
Current Account Logged in: Checking
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 2
Enter amount to withdraw: 40
Transaction Success. Successfully withdrawed from Checking Account
Current Account Logged in: Checking
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 3
Balance in Checking account:60.00
Current Account Logged in: Checking
--------- Operations -------------
1. Deposit
2. Withdraw
3. Check Balance
0. Log out
Enter your choice: 0
Successfully Logged out
--------- Main Menu -------------
1. Login
2. Register New User
0. Exit
Enter your choice: 0
Qutting.....
------------------
(program exited with code: 0)
Press any key to continue . . .
'''