From e1088f4f42480c16cd53ab8c441471c8b833f691 Mon Sep 17 00:00:00 2001 From: andy2124 Date: Fri, 22 Jul 2022 18:36:02 -0700 Subject: [PATCH 1/6] still working on --- code/Andy/python/andy_lab10_atm_v1.py | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 code/Andy/python/andy_lab10_atm_v1.py diff --git a/code/Andy/python/andy_lab10_atm_v1.py b/code/Andy/python/andy_lab10_atm_v1.py new file mode 100644 index 00000000..a151d747 --- /dev/null +++ b/code/Andy/python/andy_lab10_atm_v1.py @@ -0,0 +1,47 @@ +class Atm: + def __init__(self, balance, intrest_rate): + self.bal= 0 + self.balance = balance + self.intrest_rate= intrest_rate + + def check_balance(): + + + + + + + +# atm = ATM() # create an instance of our class +# print('Welcome to the ATM') +# while True: +# command = input('Enter a command: ') +# if command == 'balance': +# balance = atm.check_balance() # call the check_balance() method +# print(f'Your balance is ${balance}') +# elif command == 'deposit': +# amount = float(input('How much would you like to deposit? ')) +# atm.deposit(amount) # call the deposit(amount) method +# print(f'Deposited ${amount}') +# elif command == 'withdraw': +# amount = float(input('How much would you like ')) +# if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method +# atm.withdraw(amount) # call the withdraw(amount) method +# print(f'Withdrew ${amount}') +# else: +# print('Insufficient funds') +# elif command == 'interest': +# amount = atm.calc_interest() # call the calc_interest() method +# atm.deposit(amount) +# print(f'Accumulated ${amount} in interest') +# elif command == 'help': +# print('Available commands:') +# print('balance - get the current balance') +# print('deposit - deposit money') +# print('withdraw - withdraw money') +# print('interest - accumulate interest') +# print('exit - exit the program') +# elif command == 'exit': +# break +# else: +# print('Command not recognized') \ No newline at end of file From a6fed2d9130d09cf094be12b50d4875d04547d24 Mon Sep 17 00:00:00 2001 From: andy2124 Date: Mon, 25 Jul 2022 19:29:19 -0700 Subject: [PATCH 2/6] still working --- code/Andy/python/andy_lab10_atm_v1.py | 47 +++++++++++++++++---------- code/Andy/python/sample.py | 8 +++++ code/Andy/python/sample.txt | 1 + 3 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 code/Andy/python/sample.py create mode 100644 code/Andy/python/sample.txt diff --git a/code/Andy/python/andy_lab10_atm_v1.py b/code/Andy/python/andy_lab10_atm_v1.py index a151d747..76f4752d 100644 --- a/code/Andy/python/andy_lab10_atm_v1.py +++ b/code/Andy/python/andy_lab10_atm_v1.py @@ -1,28 +1,41 @@ -class Atm: - def __init__(self, balance, intrest_rate): - self.bal= 0 - self.balance = balance - self.intrest_rate= intrest_rate +class ATM: + def __init__(self, balance_arg = 0, intrest_rate_arg = .001): #positional arguments. a method. a more flexable way to do it + self.balance = balance_arg #balance_arg are local varable + self.intrest_rate = intrest_rate_arg - def check_balance(): + # def __init__(self): #positional arguments. a method + # self.balance = 0 one way to do it + # self.intrest_rate = .001 + def check_balance(self): # going into self to retrieve balance from what you have + 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 + + def deposit(self, amount): + self.balance += amount +# atm = ATM(5, .001) #putting the values for the initializer.its an object +# # print("atm bal: ", atm.balance) #just for testing but not done in real life +# # print('atm rate: ', atm.intrest_rate)#just for testing but not done in real life +# atm.check_balance() #atm is object and checkbalance is the method access the balance +# # print('calling check_balance method: ', atm.check_balance()) +# the_balance = atm.check_balance() -# atm = ATM() # create an instance of our class -# print('Welcome to the ATM') -# while True: -# command = input('Enter a command: ') -# if command == 'balance': -# balance = atm.check_balance() # call the check_balance() method -# print(f'Your balance is ${balance}') -# elif command == 'deposit': -# amount = float(input('How much would you like to deposit? ')) -# atm.deposit(amount) # call the deposit(amount) method -# print(f'Deposited ${amount}') + +atm = ATM() # create an instance of our class case sensative make the same as the class being called +print('Welcome to the ATM') +while True: + command = input('Enter a command: ') + if command == 'balance': + balance = atm.check_balance() # call the check_balance() method + print(f'Your balance is ${balance}') + elif command == 'deposit': + amount = float(input('How much would you like to deposit? ')) + atm.deposit(amount) # call the deposit(amount) method + print(f'Deposited ${amount}') # elif command == 'withdraw': # amount = float(input('How much would you like ')) # if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method diff --git a/code/Andy/python/sample.py b/code/Andy/python/sample.py new file mode 100644 index 00000000..fd0463d9 --- /dev/null +++ b/code/Andy/python/sample.py @@ -0,0 +1,8 @@ +# f = open('sample.txt') +# contents = f.read() +# print(contents) + +f = open('sample.txt') +contents = f.read() +print(contents) +f.close() \ No newline at end of file diff --git a/code/Andy/python/sample.txt b/code/Andy/python/sample.txt new file mode 100644 index 00000000..95d09f2b --- /dev/null +++ b/code/Andy/python/sample.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file From 47ac569c3981957005770e06b97f57254fb997c6 Mon Sep 17 00:00:00 2001 From: andy2124 Date: Mon, 25 Jul 2022 20:00:09 -0700 Subject: [PATCH 3/6] still working on --- code/Andy/python/andy_lab10_atm_v1.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/code/Andy/python/andy_lab10_atm_v1.py b/code/Andy/python/andy_lab10_atm_v1.py index 76f4752d..866b752c 100644 --- a/code/Andy/python/andy_lab10_atm_v1.py +++ b/code/Andy/python/andy_lab10_atm_v1.py @@ -12,7 +12,13 @@ def check_balance(self): # going into self to retrieve balance from what you hav def deposit(self, amount): self.balance += amount - + + def check_withdrawal(self, amount): #using self to get balance and amount since thats what we're checking + if self.balance >= amount: + return True + else: + return False + # atm = ATM(5, .001) #putting the values for the initializer.its an object @@ -36,13 +42,13 @@ def deposit(self, amount): amount = float(input('How much would you like to deposit? ')) atm.deposit(amount) # call the deposit(amount) method print(f'Deposited ${amount}') -# elif command == 'withdraw': -# amount = float(input('How much would you like ')) -# if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method -# atm.withdraw(amount) # call the withdraw(amount) method -# print(f'Withdrew ${amount}') -# else: -# print('Insufficient funds') + elif command == 'withdraw': + amount = float(input('How much would you like ')) + if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method + atm.withdraw(amount) # call the withdraw(amount) method + print(f'Withdrew ${amount}') + else: + print('Insufficient funds') # elif command == 'interest': # amount = atm.calc_interest() # call the calc_interest() method # atm.deposit(amount) From 6637498be0ccfe745e5a1cb61b748d1a0aa422fb Mon Sep 17 00:00:00 2001 From: andy2124 Date: Mon, 25 Jul 2022 21:16:33 -0700 Subject: [PATCH 4/6] still working --- code/Andy/python/andy_lab10_atm_v1.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/Andy/python/andy_lab10_atm_v1.py b/code/Andy/python/andy_lab10_atm_v1.py index 866b752c..61035500 100644 --- a/code/Andy/python/andy_lab10_atm_v1.py +++ b/code/Andy/python/andy_lab10_atm_v1.py @@ -18,7 +18,9 @@ def check_withdrawal(self, amount): #using self to get balance and amount since return True else: return False - + def withdraw(self, amount): + self.balance -= amount + # atm = ATM(5, .001) #putting the values for the initializer.its an object From 62c55fb54fe81aa4850ec1e86a9f774898bc623d Mon Sep 17 00:00:00 2001 From: andy2124 Date: Tue, 26 Jul 2022 21:39:09 -0700 Subject: [PATCH 5/6] almost done --- code/Andy/python/andy_lab10_atm_v1.py | 49 +++++++++++++++++---------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/code/Andy/python/andy_lab10_atm_v1.py b/code/Andy/python/andy_lab10_atm_v1.py index 61035500..b24c214c 100644 --- a/code/Andy/python/andy_lab10_atm_v1.py +++ b/code/Andy/python/andy_lab10_atm_v1.py @@ -2,7 +2,9 @@ class ATM: def __init__(self, balance_arg = 0, intrest_rate_arg = .001): #positional arguments. a method. a more flexable way to do it self.balance = balance_arg #balance_arg are local varable self.intrest_rate = intrest_rate_arg - + self.transactions = [] + + # def __init__(self): #positional arguments. a method # self.balance = 0 one way to do it # self.intrest_rate = .001 @@ -12,15 +14,25 @@ def check_balance(self): # going into self to retrieve balance from what you hav def deposit(self, amount): self.balance += amount + self.transactions.append(f'user deposited {amount}') + def check_withdrawal(self, amount): #using self to get balance and amount since thats what we're checking if self.balance >= amount: return True else: return False + def withdraw(self, amount): - self.balance -= amount + self.balance -= amount + self.transactions.append(f'user withdrew {amount}') + def calc_interest(self): + interest = self.balance * self.intrest_rate * .01 + return interest + + def print_transactions(self): + print(self.transactions) # atm = ATM(5, .001) #putting the values for the initializer.its an object @@ -51,18 +63,21 @@ def withdraw(self, amount): print(f'Withdrew ${amount}') else: print('Insufficient funds') -# elif command == 'interest': -# amount = atm.calc_interest() # call the calc_interest() method -# atm.deposit(amount) -# print(f'Accumulated ${amount} in interest') -# elif command == 'help': -# print('Available commands:') -# print('balance - get the current balance') -# print('deposit - deposit money') -# print('withdraw - withdraw money') -# print('interest - accumulate interest') -# print('exit - exit the program') -# elif command == 'exit': -# break -# else: -# print('Command not recognized') \ No newline at end of file + elif command == 'interest': + amount = atm.calc_interest() # call the calc_interest() method + atm.deposit(amount) + print(f'Accumulated ${amount} in interest') + elif command == "transactions": + atm.print_transactions() + elif command == 'help': + print('Available commands:') + print('balance - get the current balance') + print('deposit - deposit money') + print('withdraw - withdraw money') + print('interest - accumulate interest') + print('transactions - view transactions') + print('exit - exit the program') + elif command == 'exit': + break + else: + print('Command not recognized') \ No newline at end of file From 11df92d84cfb9af1df6a39da847675c3e030930b Mon Sep 17 00:00:00 2001 From: andy2124 Date: Wed, 27 Jul 2022 16:41:42 -0700 Subject: [PATCH 6/6] submitting for review --- code/Andy/python/andy_lab10_atm_v1.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/code/Andy/python/andy_lab10_atm_v1.py b/code/Andy/python/andy_lab10_atm_v1.py index b24c214c..ae2950a4 100644 --- a/code/Andy/python/andy_lab10_atm_v1.py +++ b/code/Andy/python/andy_lab10_atm_v1.py @@ -15,7 +15,7 @@ def check_balance(self): # going into self to retrieve balance from what you hav def deposit(self, amount): self.balance += amount self.transactions.append(f'user deposited {amount}') - + return self.balance def check_withdrawal(self, amount): #using self to get balance and amount since thats what we're checking if self.balance >= amount: @@ -26,13 +26,16 @@ def check_withdrawal(self, amount): #using self to get balance and amount since def withdraw(self, amount): self.balance -= amount self.transactions.append(f'user withdrew {amount}') - + return self.balance + def calc_interest(self): interest = self.balance * self.intrest_rate * .01 return interest def print_transactions(self): - print(self.transactions) + for i in self.transactions: + print(i) + return self.transactions # atm = ATM(5, .001) #putting the values for the initializer.its an object @@ -68,7 +71,8 @@ def print_transactions(self): atm.deposit(amount) print(f'Accumulated ${amount} in interest') elif command == "transactions": - atm.print_transactions() + transactions = atm.print_transactions() + print(f'your transaction history is {transactions}') elif command == 'help': print('Available commands:') print('balance - get the current balance')