0
0
Pythonprogramming~10 mins

Classes and objects 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
DCarClass
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for the class.
Using a different class name than asked.
2fill in blank
medium

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

Python
my_car = [1]()
Drag options to blanks, or click blank then click option'
ACar
Bcar
CVehicle
Dcar()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'car' instead of 'Car'.
Adding extra parentheses like 'car()()'.
3fill in blank
hard

Fix the error in the method definition to correctly initialize the Car object with a model name.

Python
class Car:
    def __init__([1], model):
        [2].model = model
Drag options to blanks, or click blank then click option'
Aself
Bcls
Cthis
Dself, self
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cls' which is for class methods.
Using 'this' which is not Python syntax.
Repeating 'self' in the parameter list.
4fill in blank
hard

Fill both blanks to add a method named display_model that prints the car's model.

Python
class Car:
    def __init__(self, model):
        self.model = model
    def [1](self):
        print(self.[2])
Drag options to blanks, or click blank then click option'
Adisplay_model
Bshow_model
Cmodel
Dmodel_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that doesn't match the instruction.
Printing an attribute name that does not exist.
5fill in blank
hard

Fill all three blanks to create a Car object with model 'Tesla' and call its display_model method.

Python
my_car = [1]([2])
my_car.[3]()
Drag options to blanks, or click blank then click option'
ACar
B'Tesla'
Cdisplay_model
Dcar
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'car' instead of 'Car'.
Forgetting quotes around the model name.
Calling a method name that does not exist.