|
1 |
| -class Atm: |
2 |
| - def __init__(self, balance, intrest_rate): |
3 |
| - self.bal= 0 |
4 |
| - self.balance = balance |
5 |
| - self.intrest_rate= intrest_rate |
| 1 | +class ATM: |
| 2 | + def __init__(self, balance_arg = 0, intrest_rate_arg = .001): #positional arguments. a method. a more flexable way to do it |
| 3 | + self.balance = balance_arg #balance_arg are local varable |
| 4 | + self.intrest_rate = intrest_rate_arg |
6 | 5 |
|
7 |
| - def check_balance(): |
| 6 | + # def __init__(self): #positional arguments. a method |
| 7 | + # self.balance = 0 one way to do it |
| 8 | + # self.intrest_rate = .001 |
8 | 9 |
|
| 10 | + def check_balance(self): # going into self to retrieve balance from what you have |
| 11 | + return self.balance #Returning is used to return a value from a function and exit the function. To return a value from a function, use the return keyword. and print means display a value dont think it'll exit the function |
| 12 | + |
| 13 | + def deposit(self, amount): |
| 14 | + self.balance += amount |
9 | 15 |
|
10 | 16 |
|
11 | 17 |
|
| 18 | +# atm = ATM(5, .001) #putting the values for the initializer.its an object |
| 19 | +# # print("atm bal: ", atm.balance) #just for testing but not done in real life |
| 20 | +# # print('atm rate: ', atm.intrest_rate)#just for testing but not done in real life |
12 | 21 |
|
| 22 | +# atm.check_balance() #atm is object and checkbalance is the method access the balance |
| 23 | +# # print('calling check_balance method: ', atm.check_balance()) |
| 24 | +# the_balance = atm.check_balance() |
13 | 25 |
|
14 | 26 |
|
15 |
| -# atm = ATM() # create an instance of our class |
16 |
| -# print('Welcome to the ATM') |
17 |
| -# while True: |
18 |
| -# command = input('Enter a command: ') |
19 |
| -# if command == 'balance': |
20 |
| -# balance = atm.check_balance() # call the check_balance() method |
21 |
| -# print(f'Your balance is ${balance}') |
22 |
| -# elif command == 'deposit': |
23 |
| -# amount = float(input('How much would you like to deposit? ')) |
24 |
| -# atm.deposit(amount) # call the deposit(amount) method |
25 |
| -# print(f'Deposited ${amount}') |
| 27 | + |
| 28 | +atm = ATM() # create an instance of our class case sensative make the same as the class being called |
| 29 | +print('Welcome to the ATM') |
| 30 | +while True: |
| 31 | + command = input('Enter a command: ') |
| 32 | + if command == 'balance': |
| 33 | + balance = atm.check_balance() # call the check_balance() method |
| 34 | + print(f'Your balance is ${balance}') |
| 35 | + elif command == 'deposit': |
| 36 | + amount = float(input('How much would you like to deposit? ')) |
| 37 | + atm.deposit(amount) # call the deposit(amount) method |
| 38 | + print(f'Deposited ${amount}') |
26 | 39 | # elif command == 'withdraw':
|
27 | 40 | # amount = float(input('How much would you like '))
|
28 | 41 | # if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method
|
|
0 commit comments