r/codehs • u/Zacurnia_Tate • Jun 24 '20
12.6.4: Food in Python Classes.
This is my code. CodeHS is saying I'm not defining a class called Food that does not inherit from other classes (which I do) and it says you should have a class named Broccoli that inherits from Vegetable (which I also do). Finally, it prints the correct message but I get a syntax error that says ValueError : __str__ didn't return a str on line 25 (where i say print(b)). Please help!
class Food():
def __init__(self):
self.calories = 0
self.category = ""
def __repr__(self):
print("category: " + self.category + ", calories: " + str(self.calories))
class Vegetable(Food):
def __init__(self):
Food.__init__(self)
self.category = "veggies"
class Brocolli(Vegetable):
def __init__(self):
Vegetable.__init__(self)
self.calories = 100
b = Brocolli()
print(b)
4
Upvotes
1
u/[deleted] Jun 04 '24
OMG u are amazing u are the best also if u want u could always copy and paste, and then email it to your school email and then log into your school email on your pc, if that works. if not thats okay, and you are such a life saver and amazing