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 are required to define a class named Car
, which includes attributes to store the car's model name and its speed.
The solution
function should instantiate a Car
object, initialize it with the given model name and speed, and then print the model name and speed of the car.
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
Car
class must havemodel
andspeed
attributes. -
model
is a string, andspeed
is 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"
The Car class should have attributes to store the model name and speed.
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help