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 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.

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 Car class must have model and speed attributes.

  • model is a string, and speed is an integer.

  • Output format should follow "Model: [model], Speed: [speed] km/h".


Example Input and Output

  • Input: model name "Tesla Model S", speed 250

  • Output: "Model: Tesla Model S, Speed: 250 km/h"

Mission
0 / 1

The Car class should have attributes to store the model name and speed.

True
False

Lecture

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help