1
+ class ATM :
2
+ def __init__ (self ):
3
+ self .balance = 0
4
+ self .transactions = []
5
+
6
+ def check_balance (self ):
7
+ return round (self .balance , 2 )
8
+
9
+ def deposit (self , amount ):
10
+ self .balance = self .balance + amount
11
+ self .transactions .append (f'user deposited ${ amount } ' )
12
+ return self .balance
13
+
14
+ def withdraw (self , amount ):
15
+ self .balance = self .balance - amount
16
+ self .transactions .append (f'user withdrew ${ amount } ' )
17
+ return self .balance
18
+
19
+ def check_withdrawal (self , amount ):
20
+ if amount > self .balance :
21
+ return False
22
+ return True
23
+
24
+ def calc_interest (self ):
25
+ calc_interest = (self .balance * .1 ) / 100
26
+ return round (calc_interest , 2 )
27
+
28
+ def print_transactions (self ):
29
+ for transaction in self .transactions :
30
+ print (transaction )
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+ atm = ATM () # create an instance of our class
39
+ print ('Welcome to the ATM' )
40
+ while True :
41
+ command = input ('Enter a command: ' )
42
+ if command == 'balance' :
43
+ balance = atm .check_balance () # call the check_balance() method
44
+ print (f'Your balance is ${ balance } ' )
45
+ elif command == 'deposit' :
46
+ amount = float (input ('How much would you like to deposit? ' ))
47
+ atm .deposit (amount ) # call the deposit(amount) method
48
+ print (f'Deposited ${ amount } ' )
49
+ elif command == 'withdraw' :
50
+ amount = float (input ('How much would you like ' ))
51
+ if atm .check_withdrawal (amount ): # call the check_withdrawal(amount) method
52
+ atm .withdraw (amount ) # call the withdraw(amount) method
53
+ print (f'Withdrew ${ amount } ' )
54
+ else :
55
+ print ('Insufficient funds' )
56
+ elif command == 'interest' :
57
+ amount = atm .calc_interest () # call the calc_interest() method
58
+ atm .deposit (amount )
59
+ print (f'Accumulated ${ amount } in interest' )
60
+ elif command == 'transactions' :
61
+ atm .print_transactions ()
62
+ elif command == 'help' :
63
+ print ('Available commands:' )
64
+ print ('balance - get the current balance' )
65
+ print ('deposit - deposit money' )
66
+ print ('withdraw - withdraw money' )
67
+ print ('interest - accumulate interest' )
68
+ print ('transactions - list of all transactions' )
69
+ print ('exit - exit the program' )
70
+
71
+ elif command == 'exit' :
72
+ break
73
+ else :
74
+ print ('Command not recognized' )
0 commit comments