Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Shape Area Calculations | Class Structures
Object Oriented Programming with Python
Avsnitt 1. Kapitel 8
single

single

Challenge: Shape Area Calculations

Svep för att visa menyn

Uppgift

Svep för att börja koda

Implement the Rectangle class according to the following requirements:

  • Implement the __init__ method to accept and store shape_id, width, and height, using self.

  • To calculate the area(), use following formula:

Area=width×height\text{Area} = \text{width} \times \text{height}
  • Provide an area() instance method that returns a string in the format: "Area: <value> <unit>", with area rounded to 2 decimal places (round()).

  • shape_id is not used in calculations — it is only needed to uniquely identify each shape instance.

  • Do not forget to remove pass in each function.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 8
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt