Skip to content

Commit 417c394

Browse files
authored
Merge pull request #123 from PdxCodeGuild/andy_lab10_atm
Andy lab10 atm submitting for review
2 parents 371f1f0 + 11df92d commit 417c394

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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
5+
self.transactions = []
6+
7+
8+
# def __init__(self): #positional arguments. a method
9+
# self.balance = 0 one way to do it
10+
# self.intrest_rate = .001
11+
12+
def check_balance(self): # going into self to retrieve balance from what you have
13+
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
14+
15+
def deposit(self, amount):
16+
self.balance += amount
17+
self.transactions.append(f'user deposited {amount}')
18+
return self.balance
19+
20+
def check_withdrawal(self, amount): #using self to get balance and amount since thats what we're checking
21+
if self.balance >= amount:
22+
return True
23+
else:
24+
return False
25+
26+
def withdraw(self, amount):
27+
self.balance -= amount
28+
self.transactions.append(f'user withdrew {amount}')
29+
return self.balance
30+
31+
def calc_interest(self):
32+
interest = self.balance * self.intrest_rate * .01
33+
return interest
34+
35+
def print_transactions(self):
36+
for i in self.transactions:
37+
print(i)
38+
return self.transactions
39+
40+
41+
# atm = ATM(5, .001) #putting the values for the initializer.its an object
42+
# # print("atm bal: ", atm.balance) #just for testing but not done in real life
43+
# # print('atm rate: ', atm.intrest_rate)#just for testing but not done in real life
44+
45+
# atm.check_balance() #atm is object and checkbalance is the method access the balance
46+
# # print('calling check_balance method: ', atm.check_balance())
47+
# the_balance = atm.check_balance()
48+
49+
50+
51+
atm = ATM() # create an instance of our class case sensative make the same as the class being called
52+
print('Welcome to the ATM')
53+
while True:
54+
command = input('Enter a command: ')
55+
if command == 'balance':
56+
balance = atm.check_balance() # call the check_balance() method
57+
print(f'Your balance is ${balance}')
58+
elif command == 'deposit':
59+
amount = float(input('How much would you like to deposit? '))
60+
atm.deposit(amount) # call the deposit(amount) method
61+
print(f'Deposited ${amount}')
62+
elif command == 'withdraw':
63+
amount = float(input('How much would you like '))
64+
if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method
65+
atm.withdraw(amount) # call the withdraw(amount) method
66+
print(f'Withdrew ${amount}')
67+
else:
68+
print('Insufficient funds')
69+
elif command == 'interest':
70+
amount = atm.calc_interest() # call the calc_interest() method
71+
atm.deposit(amount)
72+
print(f'Accumulated ${amount} in interest')
73+
elif command == "transactions":
74+
transactions = atm.print_transactions()
75+
print(f'your transaction history is {transactions}')
76+
elif command == 'help':
77+
print('Available commands:')
78+
print('balance - get the current balance')
79+
print('deposit - deposit money')
80+
print('withdraw - withdraw money')
81+
print('interest - accumulate interest')
82+
print('transactions - view transactions')
83+
print('exit - exit the program')
84+
elif command == 'exit':
85+
break
86+
else:
87+
print('Command not recognized')

code/Andy/python/sample.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# f = open('sample.txt')
2+
# contents = f.read()
3+
# print(contents)
4+
5+
f = open('sample.txt')
6+
contents = f.read()
7+
print(contents)
8+
f.close()

code/Andy/python/sample.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello world

0 commit comments

Comments
 (0)