Creating a Car Class (Challenge)
00:00
Here comes your first challenge: create a Car
class. And this challenge is relatively similar to creating the Dog
class before, but the idea here is really that you need to train these concepts. To actually train them, practically write classes and think about how to create them.
00:16 That training’s going to get you more familiar with all of the concepts and also just the practice of writing classes in Python.
00:22
Your challenge task here is to create a Car
class with two instance attributes. The first one’s going to be .color
, and that should store the name of the car’s color as a string, and then also .mileage
, which stores the number of miles on the car as an integer.
00:37
And then to test it out, you should instantiate two Car
objects, a blue car with 20,000 miles and a red car with 30,000 miles. And finally, print out their colors and mileage.
00:48
And then the output should look like: The blue car has 20,000 miles.
The red car has 30,000 miles.
00:54
And if you see a print out colors and mileage, a good way to go might be to, again, create a .__str__()
method for that. But I’ll leave it up to you how you solve this.
01:04
These are the task descriptions of the first challenge. Stop after this lesson. Open up your favorite editor and create this Car
class yourself.
01:13 And then move on to the next lesson, where you can compare to how I’m solving this challenge.
Become a Member to join the conversation.