livepython.net

184. Python Program to Find Area and Perimeter Using a Class

EasyMethods

Overview

Methods that answer a question about their object, using return.

Problem Statement

Define a class Rectangle that stores a width and a height, with two methods that return a number:

  • area(): the width times the height.
  • perimeter(): the distance all the way around, 2 * (width + height).

Read the width and the height (whole numbers), create a Rectangle, and print the results of the two methods.

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

Two lines: the width, then the height. Example:

4
3

Output

The output for that example:

Area: 12
Perimeter: 14

The tests try 4 different inputs.

Learn this firstChapter 20 · Python Methods: Functions Inside a Class
solution.py
# write your code here

EXPECTED OUTPUT

1Area: 12
2Perimeter: 14

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.