Is there a better way to write this while maintaining its current functionality? (checking balances, updating, subtracting, etc...) If so, where would I begin? I saw a code briefly in class that was for a similar questions and it looked more streamlined.
class Account:
# constructor
def __init__(self, name, account_number, balance):
self.name = name
self.account_number = account_number
self.balance = balance
# returns string representation of object
def __str__(self):
return"Account Name: {0}\nAccount Number: {1} \nAccount Balance:\
${2:.2f}".format(self.name, self.account_number, self.balance)
# add given amount to balance
def deposit(self, amount):
self.balance += amount
# subtract amount and fee from balance
def withdraw(self, amount, fee):
self.balance = self.balance - amount - fee
if __name__ == '__main__':
# make 3 objects
acct1 = Account('Guy Mann', 90453889, 100)
acct2 = Account('Donald Duck', 83504837, 100)
acct3 = Account('Joe Smith', 74773321, 100)
# print
print(acct1)
print(acct2)
print(acct3)
# deposit and print
acct1.deposit(25.85)
acct2.deposit(75.50)
acct3.deposit(50)
print(acct1)
print(acct2)
print(acct3)
# withdraw and print
acct1.withdraw(25.85, 2.50)
acct2.withdraw(75.50, 1.50)
acct3.withdraw(50, 2)
print(acct1)
print(acct2)
print(acct3)