Complete the code to change the attribute 'color' of the car object to 'red'.
class Car: def __init__(self, color): self.color = color car = Car('blue') car.color = [1] print(car.color)
Assigning 'red' to car.color changes the car's color to red.
Complete the method to update the 'speed' attribute of the Bike object.
class Bike: def __init__(self, speed): self.speed = speed def set_speed(self, new_speed): self.speed = [1] bike = Bike(10) bike.set_speed(20) print(bike.speed)
The method parameter new_speed holds the new value to assign to self.speed.
Fix the error in the method that increases the 'count' attribute by 1.
class Counter: def __init__(self): self.count = 0 def increment(self): self.count [1] 1 counter = Counter() counter.increment() print(counter.count)
The += operator adds 1 to the current value of self.count.
Fill both blanks to create a method that doubles the 'value' attribute of the object.
class Number: def __init__(self, value): self.value = value def double(self): self.value = self.value [1] [2] num = Number(5) num.double() print(num.value)
Multiplying self.value by 2 doubles its value.
Fill all three blanks to create a method that resets the 'score' attribute to zero and returns it.
class Game: def __init__(self): self.score = 10 def reset_score(self): self.score = [1] return [2] player = Game() result = player.reset_score() print([3])
The method sets self.score to 0, returns it, and the returned value is stored in result which is printed.
