So when I give the program the follow commands I get:
a = Drink(5)
b = AlcoholicDrink(4)
a. numberOfCalories
19.35
b.numberOfCalories
This is where I get the error
'AlcoholicDrink' object has no attribute 'sugar'
I have tried adding in sugar attribute to the AlcoholicDrink class but still getting the same error any ideas?
class Drink:
def __init__(self,sugar,drink = 0):
self.sugar = sugar
self.drink = drink
def numberOfCalories(self):
return self.sugar * 3.87
class AlcoholicDrink(Drink):
def __init__(self,alcohol):
self.alcohol = alcohol
def numberOfCalories(self):
if self.alcohol > 0:
self.alcohol * 7.0 + self.sugar
else:
super.numberOfCalories()
__init__is the instance initializer, the constructor is__new__; your classes are using the__new__method of the parentobjectclass, since they don't override__new__(and there's rarely a need to do so).