Tell us what’s happening:
Hi, am stuck on test 16 regarding the str output when the class is printed. I painstakingly got the desired output but fail to bypass the test 16 check. Did a lot of manual formatting since I don’t think it was taught anywhere on how to easily align the strings and I saw it as a stupid challenge. Looking around on the forum, people seem to pull the functions out of thin air as well. Would appreciate if someone can look at my mess and give me some tips on how to approach it? Thank you ![]()
Your code so far
class Category:
def __init__(self,name):
self.name=name
self.ledger=[]
self.balance=0
def deposit(self,amount,description=''):
self.balance+=amount
self.ledger.append({'amount': amount, 'description': description})
def withdraw(self,amount,description=''):
if self.check_funds(amount):
withdrawn_amount=amount*-1
self.balance+=withdrawn_amount
self.ledger.append({'amount': amount*-1, 'description': description})
return True
else:
return False
def get_balance(self):
return self.balance
def transfer(self,amount,destination):
if self.check_funds(amount):
self.withdraw(amount,f'Transfer to {destination.name}')
destination.deposit(amount,f'Transfer from {self.name}')
return True
else:
return False
def check_funds(self,amount):
if amount>self.balance:
return False
else:
return True
def __str__(self):
return str(self.full_display())
def full_display(self):
#header
header=''
header_char_count=0
asterisk_count=30
for character in self.name:
header_char_count+=1
asterisks_firsthalf = (asterisk_count-header_char_count)//2
asterisks_secondhalf = asterisk_count-asterisks_firsthalf-header_char_count
header+=('*' * asterisks_firsthalf)
header+=(self.name)
header+=('*' * asterisks_secondhalf)
print(header)
#ledgers
totalsum=0
ledger_char_count=0
for dictionary in self.ledger:
final_line=''
description_line=''
character_limit=23
for character in dictionary['description']:
if character_limit>0:
description_line+=character
character_limit-=1
final_line+=description_line
for space_padding in range(len(final_line),26):
if character_limit>0:
final_line+=' '
character_limit-=1
amount_str=''
remaining_char=7
if not isinstance(dictionary['amount'],float):
amount_str+=str((dictionary['amount']))+'.00'
totalsum+=dictionary['amount']
else:
amount_str+=str((dictionary['amount']))
totalsum+=dictionary['amount']
for remaining_padding in range(len(amount_str),7):
if remaining_padding<7:
final_line+=' '
print(final_line+amount_str)
return f'Total: {totalsum}'
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0
Challenge Information:
Build a Budget App - Build a Budget App