Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Object-Oriented Polymorphism
00:00
5 left

Object-Oriented Polymorphism

MediumPython

Problem

Explain the concept of polymorphism in object-oriented programming. Implement it by creating shape classes with a common area() method, then calculate the total area from JSON-compatible shape descriptions. Use def calculate_total_area(shapes):; each shape is a dictionary with either type: "circle", radius or type: "rectangle", width, height, and return the total area rounded to two decimal places.

Constraints

  • 0 <= len(shapes) <= 10^4
  • Each shape has type "circle" or "rectangle"
  • Dimensions are non-negative numbers
  • Return the total rounded to two decimal places

Function Signature

def calculate_total_area(shapes):
Interviewer

Your question is Object-Oriented Polymorphism. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.