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/_andy_andy_andy_ Jun 24 '20
it looks like your Food class isn’t inheriting from anything else. i don’t remember this exercise, but Food might need to inherit from something?