Skip to content

Instantly share code, notes, and snippets.

View lahiiru's full-sized avatar

Lahiru Jayakody lahiiru

View GitHub Profile
@lahiiru
lahiiru / python-work-pieces-exercise.md
Last active December 27, 2022 11:10
Python Exercise - Using python classes to model problems

Assume you are assembling differnt kind of work pieces and making products. You need to build a WorkPiece class which can be reused to build differnt kind of pieces with differnt shapes, materials etc. You will finally add those pieces by + sign and make a composite object. So you can print information regarding the composite object.

Example psudocode will be like below.

wooden_top = WorkPiece(material=Wood, shape=Cylinder, radius=1, height=0.1)
metal_leg = WorkPiece(material=Steel, shape=Cylinder, radius=0.1, height=2)
chair = wooden_top + 4 * metal_leg