Skip to content

Instantly share code, notes, and snippets.

@lahiiru
Last active December 27, 2022 11:10
Show Gist options
  • Save lahiiru/4e993c1ffdbf7089c997f4f0c54472eb to your computer and use it in GitHub Desktop.
Save lahiiru/4e993c1ffdbf7089c997f4f0c54472eb to your computer and use it in GitHub Desktop.
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

chair.print_material_volume_breakdown()
chair.print_total_cost()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment