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

single

Challenge: Shape Area Calculations

Sveip for å vise menyen

Oppgave

Sveip for å begynne å kode

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 desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 8
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt