0
0
Pythonprogramming~10 mins

Real-world modeling using 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
BEngine
CDrive
DVehicle
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like Vehicle instead of Car.
2fill in blank
medium

Complete the code to add an __init__ method that sets the car's color.

Python
class Car:
    def __init__(self, [1]):
        self.color = color
Drag options to blanks, or click blank then click option'
Amodel
Bspeed
Csize
Dcolor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not match the attribute name.
3fill in blank
hard

Fix the error in the method to return the car's color.

Python
class Car:
    def __init__(self, color):
        self.color = color
    def get_color(self):
        return self.[1]
Drag options to blanks, or click blank then click option'
Acolor
Bcolour
CColor
Dcol
Attempts:
3 left
💡 Hint
Common Mistakes
Using a misspelled or differently cased attribute name.
4fill in blank
hard

Fill both blanks to create a method that changes the car's color.

Python
class Car:
    def __init__(self, color):
        self.color = color
    def [1](self, [2]):
        self.color = new_color
Drag options to blanks, or click blank then click option'
Achange_color
Bcolor
Cnew_color
Dget_color
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not match the action or a parameter name that doesn't match the assignment.
5fill in blank
hard

Fill all three blanks to create a Car object and print its color.

Python
my_car = [1]([2])
print(my_car.[3]())
Drag options to blanks, or click blank then click option'
ACar
B'red'
Cget_color
Dcolor
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the color string or calling the attribute directly instead of the method.