Tell us what’s happening:
I am having an issue in the Python curriculum where whenever I try during a workshop or lab to use sep=, end=, or, in some circumstances, ANSI escape codes, [object, Object] is printed. For example, should I attempt the following, this is what will happen:
print(“Spherical”, “Bee”, sep=“”) #Output: Spherical Toast [object, Object]
I am unsure what the problem may be or how to solve it, nor have I found anything addressing it. Any help is appreciated.
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 get_balance(self):
balance = 0
for index, transaction in enumerate(self.ledger):
balance += self.ledger[index]["amount"]
return balance
def check_funds(self, amount):
if amount > self.get_balance():
return False
else:
return True
def withdraw(self, amount, description=""):
if self.check_funds(amount):
self.ledger.append({"amount" : -amount, "description": description})
return True
else:
return False
def transfer(self, amount, other_instance):
if self.check_funds(amount):
self.withdraw(amount, f"Transfer to {other_instance.name}")
other_instance.deposit(amount, f"Transfer from {self.name}")
return True
else:
return False
def __str__(self):
print("*" * int((30 - len(self.name))/2), self.name, "*" *
(30 - (len(self.name) + int((30 - len(self.name))/2))), sep="")
for index, entry in enumerate(self.ledger):
description = ""
amount = "{:.2f}".format(self.ledger[index]["amount"])
if len(self.ledger[index]["description"]) >= 23:
description = self.ledger[index]["description"][:23]
else:
description = self.ledger[index]["description"]
if self.ledger[index]["amount"] >=7:
amount = amount[-7:]
else:
pass
print(description, " " * (30 - (len(description) + len(amount))), amount, sep="")
return f"Total: {self.get_balance()}"
def create_spend_chart(categories):
print("Percentage spent by category")
index = 100
while index > 0:
print(f"{index}|\n\033[1C ", end="")
index = index - 10
food = Category("Food")
clothing = Category("Clothing")
auto = Category("Auto")
rent = Category("Rent")
food.deposit(1000, "initial deposit")
food.withdraw(10.15, "groceries")
food.withdraw(15.89, "restaurant and more food for dessert")
food.transfer(50, clothing)
print(food)
clothing.withdraw(30, "socks")
auto.withdraw(20, "seat cushions")
rent = (400, "monthly rent")
category_list = [food, clothing, auto, rent]
create_spend_chart(category_list)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0
Challenge Information:
Build a Budget App - Build a Budget App