Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Class Inheritance with Print Description

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Class Inheritance with Print Description. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

NetApp fleet tooling represents transport assets used to support infrastructure operations. Implement a class hierarchy with a base Vehicle class and specialized Car and Plane subclasses. Each class must provide a Print_description method that returns a formatted description.

Implement build_descriptions(vehicles), which receives vehicle records and returns descriptions in the same order. The function must instantiate the appropriate class based on the record's type field and use polymorphism to call Print_description without checking the subclass after construction.

Formal Specification

  • Input: vehicles, a list of dictionaries. Every dictionary contains type and name.
  • A vehicle record has no additional fields.
  • A car record contains integer doors.
  • A plane record contains numeric wingspan.
  • Output: a list of strings, one description per input record.
  • Use the exact formats shown in the examples.

Constraints

  • 1 <= len(vehicles) <= 10^4
  • Each name contains 1 to 100 characters
  • 2 <= doors <= 6
  • 1.0 <= wingspan <= 1000.0
  • Every record type is vehicle, car, or plane

Function Signature

def build_descriptions(vehicles):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output