#62MediumClasses· Polymorphism
Inheritance & Polymorphism: Shape Hierarchy
Input format
`shapes`: a list of `[kind, ...dimensions]` lists with positive numbers.
Output format
A list of description strings.
Examples
Input: shapes = [["circle",1],["rectangle",2,3]]
Output: ["Circle: area=3.14, perimeter=6.28","Rectangle: area=6.00, perimeter=10.00"]
Circle area is pi * r^2 = 3.14 and circumference 2 * pi * r = 6.28.
Input: shapes = [["square",4],["triangle",3,4,5],["triangle",1,2,3]]
Output: ["Square: area=16.00, perimeter=16.00","Triangle: area=6.00, perimeter=12.00","Triangle: invalid sides"]
A square is a rectangle with equal sides. 1 + 2 is not greater than 3, so the last triangle is invalid.
Constraints
- 0 <= len(shapes) <= 100
- 0 < dimension <= 1000
- #python
- #oop
- #inheritance
- #polymorphism
- #abc
