Adding a .drive() Method (Challenge)
00:00
The challenge continues. Your next task is to let the cars drive. So, based on the Car
class that you built previously, you should modify it.
00:09
Add another instance method called .drive()
. This .drive()
instance method is going to take a number as an argument and add that number to the .mileage
instance attribute.
00:19
So that means that you should be able to drive a car. So, whatever mileage it has, if you call .drive()
on it and pass it an integer, its .mileage
instance attribute should be incremented by that number.
00:31
Then you can test it by instantiating a Car
with 0
miles and then call .drive()
, passing it 100
. And finally, then also print the .mileage
attribute to check that it’s actually now set to 100
, not 0
anymore as you instantiated it.
00:47
So, use the Car
class that you used before, try to add this .drive()
functionality to it. Then move on to the next lesson and example solution of how I’m going to do this.
Become a Member to join the conversation.