hello everyone, I am currently working on the budget app, and am having some problems in the formatting the list of items part of the project.
Here is my code:
`class Category:
def __init__(self, item):
self.item = item
self.ledger = list()
self.balance = 0
def deposit(self, deposit_amt, deposit_descrpt=None):
self.deposit_amt = deposit_amt
self.deposit_descrpt = deposit_descrpt
self.balance = 0 + deposit_amt
if self.deposit_descrpt == None:
self.deposit_descrpt = " "
x = {"amount": self.deposit_amt, "description": self.deposit_descrpt}
self.ledger.append(x)
def get_balance(self):
return self.balance
def check_funds(self, amt):
self.amt = amt
if self.amt > self.get_balance():
return False
return True
def withdraw(self, withdraw_amt, withdraw_descrpt = None):
self.withdraw_amt = withdraw_amt
self.withdraw_descrpt = withdraw_descrpt
if self.withdraw_descrpt == None:
y = {"amount": (-1) * self.withdraw_amt, "description": " "}
else:
y = {"amount": (-1) * self.withdraw_amt, "description": self.withdraw_descrpt}
if self.check_funds(self.withdraw_amt):
self.ledger.append(y)
self.balance = 0 - self.withdraw_amt
return True
return False
def transfer(self, transfer_amt, item2):
self.transfer_amt = transfer_amt
self.item2 = item2
if self.transfer_amt > self.deposit_amt:
return False
else:
x = "Transfer to {}".format(item2)
self.withdraw(self.transfer_amt, x)
str(self.ledger.append(self.withdraw(self.transfer_amt, x)))
z = "Transfer to {}".format(self.item)
self.deposit(self.transfer_amt, z)
self.ledger.append(self.deposit(self.transfer_amt, z))
return True
def __str__(self):
stars = (int(30 - len(self.item)/2) * "*") + self.item + (int(30 - len(self.item)/2) * "*")
for dictionary in self.ledger:
return dictionary.values()
#code included in the main file by FCC:
food = Category(“Food”)
food.deposit(1000, “initial deposit”)
food.withdraw(10.15, “groceries”)
food.withdraw(15.89, “restaurant and more food for dessert”)
print(food.get_balance())
clothing = Category(“Clothing”)
food.transfer(50, clothing)
clothing.withdraw(25.55)
clothing.withdraw(100)
auto = Category(“Auto”)
auto.deposit(1000, “initial deposit”)
auto.withdraw(15)
print(food)
print(clothing)
`
currently my editor is giving me this error:
Traceback (most recent call last): File "/home/beatrix/PycharmProjects3/budjet_app/main.py", line 101, in <module> food.transfer(50, clothing) File "/home/beatrix/PycharmProjects3/budjet_app/main.py", line 77, in transfer x = "Transfer to {}".format(item2) TypeError: __str__ returned non-string (type NoneType)
Now i have done some research online before coming here, and found that this error occurs frequently when one tries to use a “print” statement in the str method (which is not my case) , or when the output in the return statement is not a string. In that case the output should be surrounded by “str()” to fix the problem.
I have tried surrounding both the output of the str method with str() and the line 77 variable pointed out by python with “str()” but none of these two ideas worked. So at this point I am a bit lost for ideas on how to proceed, as nowhere online have I seen a similar problem, Is there something about the str method that I am missing?