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

single

Challenge: Shape Area Calculations

Glissez pour afficher le menu

Tâche

Glissez pour commencer à coder

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.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 8
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt