Skip to main content
Practice

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 both the car's model name and its 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 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"

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.