|
| 1 | +class ATM: |
| 2 | + def __init__(self, balance, interest): |
| 3 | + self.balance = balance |
| 4 | + self.interest = interest |
| 5 | + self.transactions = [] |
| 6 | + |
| 7 | + def check_balance (self): |
| 8 | + return self.balance |
| 9 | + |
| 10 | + def deposit(self, amount): |
| 11 | + self.balance += amount |
| 12 | + self.transactions.append(f"Deposited {amount}. New balance is {self.balance}") |
| 13 | + |
| 14 | + |
| 15 | + def check_withdrawal(self, amount): |
| 16 | + if self.balance >= amount: |
| 17 | + return True |
| 18 | + if self.balance < amount: |
| 19 | + return False |
| 20 | + |
| 21 | + def withdraw(self, amount): |
| 22 | + self.balance -= amount |
| 23 | + self.transactions.append(f"Withdrew {amount}. New balance is {self.balance}") |
| 24 | + |
| 25 | + def calc_interest(self): |
| 26 | + try: |
| 27 | + t = float(input("Enter the number of years in intergers: ")) |
| 28 | + r = self.interest |
| 29 | + p = self.balance |
| 30 | + result = f'Your interest is: ${t * r * p}\nYour balance after interest is: ${p - (p * r * t)}' |
| 31 | + return result |
| 32 | + except: |
| 33 | + return "We were unable to process that input\nMake sure you only input integers" |
| 34 | + |
| 35 | + |
| 36 | +lines_for_looks = "--------------------" |
| 37 | +print('Welcome to the ATM') |
| 38 | + |
| 39 | +atm = ATM(0, 0.005) |
| 40 | +while True: |
| 41 | + |
| 42 | + command = input('Enter a command: ') |
| 43 | + |
| 44 | + if command == 'balance': |
| 45 | + balance = atm.check_balance() |
| 46 | + print(lines_for_looks) |
| 47 | + print(f'Your balance is ${balance}') |
| 48 | + |
| 49 | + elif command == 'deposit': |
| 50 | + try: |
| 51 | + amount = float(input('How much would you like to deposit? ')) |
| 52 | + atm.deposit(amount) |
| 53 | + print(lines_for_looks) |
| 54 | + print(f'Deposited ${amount}') |
| 55 | + except: |
| 56 | + print(lines_for_looks) |
| 57 | + print("We were unable to process that input\nMake sure you only input integers") |
| 58 | + |
| 59 | + elif command == 'withdraw': |
| 60 | + try: |
| 61 | + amount = float(input('How much would you like ')) |
| 62 | + if atm.check_withdrawal(amount): |
| 63 | + atm.withdraw(amount) |
| 64 | + print(lines_for_looks) |
| 65 | + print(f'Withdrew ${amount}') |
| 66 | + else: |
| 67 | + print(lines_for_looks) |
| 68 | + print('Insufficient funds') |
| 69 | + except: |
| 70 | + print(lines_for_looks) |
| 71 | + print("We were unable to process that input\nMake sure you only input integers") |
| 72 | + |
| 73 | + elif command == 'interest': |
| 74 | + print(lines_for_looks) |
| 75 | + print(atm.calc_interest()) |
| 76 | + |
| 77 | + elif command == 'transactions': |
| 78 | + print(lines_for_looks) |
| 79 | + print(f'TRANSACTIONS - {atm.transactions}') |
| 80 | + |
| 81 | + elif command == 'help': |
| 82 | + print(lines_for_looks) |
| 83 | + print('Available commands:') |
| 84 | + print('balance - get the current balance') |
| 85 | + print('deposit - deposit money') |
| 86 | + print('withdraw - withdraw money') |
| 87 | + print('interest - accumulate interest') |
| 88 | + print('exit - exit the program') |
| 89 | + print('transactions - view recent transactions') |
| 90 | + |
| 91 | + elif command == 'exit': |
| 92 | + break |
| 93 | + |
| 94 | + else: |
| 95 | + print(lines_for_looks) |
| 96 | + print('Command not recognized') |
| 97 | + |
| 98 | + |
0 commit comments