Lecture
Coding Quiz - Creating a Car Class
In this coding quiz, you will write a simple solution function that involves the basics of classes in Python.
You need to define a class named Car that includes attributes to store the car’s model name and speed.
The solution function should create a Car object, initialize it with the given model name and speed, and print both attributes.
Code Format
class Car: def __init__(self, model, speed): # Write your code here def solution(model, speed): # Write your code here return # Write your code here
Constraints
-
The
Carclass must havemodelandspeedattributes. -
modelis a string, andspeedis an integer. -
Output format should follow "Model: [model], Speed: [speed] km/h".
Example Input and Output
-
Input: model name
"Tesla Model S", speed250 -
Output:
"Model: Tesla Model S, Speed: 250 km/h"
Lessons in this chapter · Basics of Object-Oriented Programming - Classes, Instances, Attributes, Methods
- 1. Introduction to Object-Oriented Programming (OOP)
- 2. Everything About Python - What is an Object?
- 3. Relationship Between Class and Instance
- 4. How to Declare a Class in Python
- 5. What is a Class Constructor?
- 6. The Relationship Between Classes and Methods
- 7. Multiple-choice quiz
- 8. Inheritance of Class Attributes and Methods
- 9. How to Bundle Attributes and Methods with Encapsulation
- 10. Adding Flexibility to Objects with Polymorphism
- 11. Coding Quiz - Creating a Car Class
- 12. Multiple-choice quiz
- 13. Fill-in-the-blank quiz
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help