class Category:
def __init__(self, category):
self.category = category
self.ledger = []
self.balance = 0
self.spent_balance = 0
def __repr__(self):
return self.category
def format(self, amount, description):
#turning interger to exacly 2 point float number
self.category += f"\n{description.ljust(23)[:23]}" +\
f"{amount:.2f}".rjust(7)[:7]
return self.category
def deposit(self, amount, description = ''):
self.ledger.append({'amount': amount, 'description': description})
self.balance += amount
self.category = "\n" + str(self.category).center(30, '*')
self.format(amount, description)
def withdraw(self, amount, description = ''):
#subtracting a sub-string from a string
self.category = self.category.replace(f"\nTotal: {self.balance:.2f}\n", '')
if self.check_funds(amount):
self.ledger.append({'amount': -amount, 'description': description})
self.balance -= amount
self.spent_balance += amount
self.format(-amount, description)
self.category += f"\nTotal: {self.balance:.2f}\n"
return True
return False
def get_balance(self):
return self.balance
def transfer(self, amount, category):
if self.check_funds(amount):
self.withdraw(amount, f'transfer to {category}')
#I cant call deposit on my new category and have it in a new ledger??
Category(category).deposit(amount, f'transfer from {self.category}')
return True
return False
def check_funds(self, amount):
if amount > self.get_balance():
return False
return True
What’s your question?
[quote=“mohamedelmir, post:1, topic:741147”]
#I cant call deposit on my new category and have it in a new ledger??
[/quote
when i call transfer on a category i cant deposit in a seperate ledger
Could you be a bit more specific? What are you trying to do, what happens instead? What have you tried so far?
these are the errors i get when testing
7. Calling the transfer method on a category object
should create a specific ledger item in that category object.
11. The transfer method should create a specific ledger item
in the category object passed as its argument.
category
is already the other category
, you don’t need to instantiate a new one with Category