Tell us what’s happening:
In test 16, printing the ledger activity for a given category, I think my output is matching the example but I’m failing the test. There isn’t a line feed after the total line, so I know it’s not that. Any help you can provide will be greatly appreciated.
Here’s my output (it lines up correctly in the console):
Food
initial deposit 1000.00
groceries -10.15
restaurant and more foo -15.89
Transfer to Clothing -50.00
Total: 923.96
Your code so far
class Category:
def __init__(self, name):
self.name = name
self.ledger = []
def deposit(self, amount, description=''):
self.ledger.append({'amount': amount, 'description': description})
def withdraw(self, amount, description=''):
if self.check_funds(amount):
self.ledger.append({'amount': -amount, 'description': description})
return True
return False
def check_funds(self, amount):
if amount > self.get_balance():
return False
return True
def get_balance(self):
balance = 0
for tx in self.ledger:
balance += tx['amount']
return balance
def transfer(self, amount, other):
if self.check_funds(amount):
self.ledger.append({'amount': -amount, 'description': f'Transfer to {other.name}'})
other.ledger.append({'amount': amount, 'description': f'Transfer from {self.name}'})
return True
return False
def __str__(self):
print_string = ''
padding_left = (30 - len(self.name))//2
padding_right = 30 - len(self.name) - padding_left
print_string += f"{('*' * padding_left)}{self.name}{('*' * padding_right)}\n"
for tx in self.ledger:
description = tx['description'][:23]
amount = f"{tx['amount']:.2f}".rjust(7)
print_string += f"{description.ljust(23)} {amount}\n"
print_string +=f"Total: {self.get_balance()}"
return print_string
def create_spend_chart(categories):
pass
food = Category('Food')
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
print(food)
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15 Ddg/26.1
Challenge Information:
Build a Budget App - Build a Budget App