My code]
class Category:
def __init__(self, name):
self.name = name
self.ledger = []
def __str__(self):
returnvalue = ""
title = ("*" * 13)+self.name+("*"*13)
titlelen = len(title)
items = ""
total = ""
tamount = []
tdesc = []
totalamt = 0
returnvalue += title
returnvalue += "\n"
for item in self.ledger:
thamount = self.getamt(item)
thdesc = self.getdesc(item)
tamount.append(thamount)
tdesc.append(thdesc)
for i in range(len(tdesc)):
newdesc = ""
if tdesc[i] == "deposit":
tdesc[i] = "initial deposit"
if len(tdesc[i]) + len(tamount[i]) > titlelen:
newlen = (len(tdesc[i])-(len(tdesc[i]) - titlelen)) - len(tamount[i]) - 1
for j in range(newlen):
newdesc += tdesc[i][j]
tdesc[i] = newdesc
if "." not in tamount[i]:
newtdesc = tamount[i] + ".00"
tamount[i] = newtdesc
for i in range(len(tdesc)):
totalamt += float(tamount[i])
#Add to items var
for i in range(len(tamount)):
items += tdesc[i]
spaceform = titlelen - (len(tdesc[i])+len(tamount[i]))
items += " " * (titlelen - (len(tdesc[i])+len(tamount[i])))
items += tamount[i]
items += "\n"
returnvalue += items
total = "Total: " + str(totalamt)
returnvalue += total
return returnvalue
def getamt(self, dicts):
newdicts = ""
for i in str(dicts):
digits = "1234567890.-"
if i in digits:
newdicts += i
return newdicts
def getdesc(self, dicts):
switch = 0
switch2 = 0
switch3 = 0
switch4 = 0
description = ""
description2 = ""
for i in str(dicts):
if i == ",":
switch = 1
if switch == 1:
if i == ":":
switch2 = 1
if switch2 == 1:
if i == " ":
switch3 = 1
if switch3 == 1:
if i == "'":
switch4 = 1
if switch4 == 1:
description += i
for i in description:
nochar = "'}"
if i not in nochar:
description2 += i
return description2
def deposit(self, amount, description = ""):
self.ledger.append({"amount":amount,"description":description})
return True
def get_balance(self):
return sum(item["amount"] for item in self.ledger)
def check_funds(self, amount):
return amount <= self.get_balance()
def withdraw(self, amount, description = ""):
if not self.check_funds(amount):
return False
self.ledger.append({"amount": -amount, "description": description})
return True
def transfer(self, amount, destination_category):
if not self.check_funds(amount):
return False
self.ledger.append({"amount": -amount, "description": f"Transfer to {destination_category.name}"})
destination_category.ledger.append({"amount": amount, "description": f"Transfer from {self.name}"})
return True
def create_spend_chart(categories):
pass
food = Category('Food')
food.deposit(1000, '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)
doesn’t complete step 16 despite print the page. I’m really confused why even though I followed the instructions. Can someone help me?