Car Class

 Problem Statement

Suggest Edit

Design a class Car having parameterized constructor that takes two arguments as an input i.e noOfGear and color and a printCarInfo method that prints the CarInfo i.e noOfGear and color.

Design another class RaceCar having parameterized constructor has an additional attribute maxSpeed and printRaceCarInfo method that prints the RaceCarInfo i.e noOfGear, color and maxSpeed.

Note: You have to create an object of class RaceCar and call the printRaceCarInfo method.

Input Format:

The first line of input contains a single integer representing noOfGear.

The second line of input contains a string without any preceding and trailing spaces, denoting the color of the car.

The third line of input contains a single Integer representing maxSpeed.

Output Format:

The first line of output prints the number of gears in the car
The second line of output prints the color of the car.
The third line of output prints the maximum speed of the car.
Sample Input 1:
5
red
1000
Sample Output 1:
noOfGear: 5
color: red
maxSpeed: 1000
Explanation Of Sample Output 1:
When we call the printInfo function, all the info related to the car will be printed the same as the above format.

from sys import stdin


class Car:
    def __init__(self,noOfGear,color):
        self.noOfGear=noOfGear
        self.color=color
    def printCarInfo(self):
        print('noOfGear: ',noOfGear)
        print('color: ',color)

    #Write your constructor and printCarInfo method here.
        
        


class RaceCar(Car):
    def __init__(self,noOfGear,color,maxSpeed):
        super().__init__(noOfGear,color)
        self.maxSpeed=maxSpeed
        
    def printRaceCarInfo(self):
        print('noOfGear: ',self.noOfGear)
        print('color: ',self.color)
        print('maxSpeed: ',self.maxSpeed)
    
    #Write your constructor and printRaceCarInfo method here.
c=RaceCar(input(),input(),input())
c.printRaceCarInfo()











Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings