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

single

Challenge: Shape Area Calculations

Pyyhkäise näyttääksesi valikon

Tehtävä

Pyyhkäise aloittaaksesi koodauksen

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.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 8
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt