diff --git a/bankaccount b/bankaccount new file mode 100644 index 000000000000..587ca7d189cc --- /dev/null +++ b/bankaccount @@ -0,0 +1,33 @@ +class Account: + def __init__(self, filepath): + self.filepath=filepath + with open(filepath, 'r') as file: + self.balance = int(file.read()) + def withdraw(self, amount): + self.balance=self.balance - amount + def deposit(self,amount): + self.balance=self.balance + amount + + def commit(self): + with open(self.filepath,'w') as file: + file.write(str(self.balance)) +class Checking(Account): + def __init__(self,filepath, fee): + Account.__init__(self,filepath) + self.fee=fee + def transfer(self,amount): + self.balance=self.balance-amount-self.fee + + +"""checking = Checking("balance.txt", 2) +#checking.deposit(10) +checking.transfer(10) +print("available balance:",checking.balance) +checking.commit()""" + +account = Account("balance.txt") +print("total balance:",account.balance) +account.withdraw(90) +account.deposit(10) +print("available balance:",account.balance) +account.commit()