Challenge
Note
Private methods and attributes of the parent class are not available in the child's class.
The Animal
class:
1234567class Animal: def __init__(self, name = None, age = None): self.__name = name self.__age = age def move(self): print('Animal is moving...')
Uppgift
Swipe to start coding
- Create a class
Cat
that inherits theAnimal
class. - Create the
eat
method. - Create a
5
kg10
years old'Lola'
cat. - Move the cat (using the
move()
method from theAnimal
class). - 'Feed' the cat (using the
eat()
method from theCat
class).
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 2
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Suggested prompts:
Sammanfatta detta kapitel
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 7.69
Challenge
Svep för att visa menyn
Note
Private methods and attributes of the parent class are not available in the child's class.
The Animal
class:
1234567class Animal: def __init__(self, name = None, age = None): self.__name = name self.__age = age def move(self): print('Animal is moving...')
Uppgift
Swipe to start coding
- Create a class
Cat
that inherits theAnimal
class. - Create the
eat
method. - Create a
5
kg10
years old'Lola'
cat. - Move the cat (using the
move()
method from theAnimal
class). - 'Feed' the cat (using the
eat()
method from theCat
class).
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Awesome!
Completion rate improved to 7.69Avsnitt 3. Kapitel 2
single