Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a class named Car.
Python
class [1]: pass
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like Vehicle instead of Car.
✗ Incorrect
The class name should be Car to model a car object.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not match the attribute name.
✗ Incorrect
The parameter color is needed to set the car's color attribute.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a misspelled or differently cased attribute name.
✗ Incorrect
The attribute is named color, so the method should return self.color.
4fill in blank
hardFill 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'
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.
✗ Incorrect
The method name should be change_color and the parameter new_color to update the color.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the color string or calling the attribute directly instead of the method.
✗ Incorrect
Create a Car object with color 'red' and call the get_color() method to print it.