0
0
Pythonprogramming~10 mins

OOP principles overview in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a class named Car.

Python
class [1]:
    pass
Drag options to blanks, or click blank then click option'
Acar
BCar
Cvehicle
DAuto
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for classes.
Using unrelated names.
2fill in blank
medium

Complete the code to create an object my_car from the Car class.

Python
my_car = [1]()
Drag options to blanks, or click blank then click option'
Acar
BAuto
Cvehicle
DCar
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase class names when creating objects.
Forgetting parentheses after the class name.
3fill in blank
hard

Fix the error in the method definition to correctly define the constructor.

Python
class Car:
    def [1](self, make):
        self.make = make
Drag options to blanks, or click blank then click option'
A__init__
Binit
Cconstructor
Dinitialize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'init' without underscores.
Using other names like 'constructor' or 'initialize'.
4fill in blank
hard

Fill both blanks to define a method display_make that prints the car's make.

Python
class Car:
    def __init__(self, make):
        self.make = make
    def [1](self):
        print(self.[2])
Drag options to blanks, or click blank then click option'
Adisplay_make
Bmake
Cmodel
Dshow_make
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names.
Printing an attribute that does not exist.
5fill in blank
hard

Fill all three blanks to create a subclass ElectricCar that inherits from Car and adds a battery_size attribute.

Python
class [1]([2]):
    def __init__(self, make, battery_size):
        super().[3](make)
        self.battery_size = battery_size
Drag options to blanks, or click blank then click option'
AElectricCar
BCar
C__init__
DBatteryCar
Attempts:
3 left
💡 Hint
Common Mistakes
Not calling the parent constructor properly.
Using wrong class or method names.