द्विआयामी ज्यामिति के आकृतियों के क्लासेज़

2-आयामी ज्यामितीय आकृतियों में बहुभुज (Polygon) आधारभूत होते हैं। इस चुनौती में, आपका काम चार प्रकार के बहुभुजों का प्रतिनिधित्व करने वाले क्लासेज़ बनाना है: Polygon, Triangle, Rectangle, और Pentagon

एक बहुभुज उसकी भुजाओं की संख्या से परिभाषित होता है। इसलिए, Polygon क्लास में एक एट्रिब्यूट sides होना चाहिए जो बहुभुज की भुजाओं की संख्या का प्रतिनिधित्व करे।

Polygon क्लास में एक मेथड describe() भी होना चाहिए जो कॉल करने पर "A polygon" प्रिंट करे।

अब, Triangle, Rectangle, और Pentagon क्लासेज़ बनाएं जो Polygon क्लास से इनहेरिट करें। इन प्रत्येक क्लासेज़ को describe() मेथड को ओवरराइड करना चाहिए ताकि कॉल करने पर क्रमशः "A triangle", "A rectangle", और "A pentagon" प्रिंट हो। इस तरह, प्रत्येक विशेष बहुभुज describe() मेथड कॉल करने पर अपने आप को घोषित कर सकेगा।

इनपुट

आउटपुट

polygon, triangle, rectangle, pentagon = Polygon(10), Triangle(), Rectangle(), Pentagon(); polygon.describe(); print('Polygon sides:', polygon.sides); triangle.describe(); print('Triangle sides:', triangle.sides); rectangle.describe(); print('Rectangle sides:', rectangle.sides); pentagon.describe()

A polygon
Polygon sides: 10
A triangle
Triangle sides: 3
A rectangle
Rectangle sides: 4
A pentagon

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue