Start free

Novice · Arithmetic · 18 of 264

Rectangle area and perimeter

Read the width and height of a rectangle and print its area and its perimeter.

Input: width and height, whole numbers, one per line. Output: Area: <area> on the first line, Perimeter: <perimeter> on the second.

Examples

Input
3
4
Output
Area: 12
Perimeter: 14
Input
10
10
Output
Area: 100
Perimeter: 40
Input
1
7
Output
Area: 7
Perimeter: 16

One more test checks other inputs when you press Check.

Stuck? The idea behind arithmetic

input() always gives text: turn it into a whole number with int() or a decimal with float() before doing sums.

+ - * / work as in maths; / always gives a decimal. // divides and drops the remainder, % gives the remainder, ** raises to a power.

a = int(input())
b = int(input())
print(a + b)
print(a // b, a % b)

Watch for: "5" + "3" is "53", not 8: if a sum joins numbers together, an int() is missing.

All the arithmetic exercises
Your code
Opening the code editor…
Python 3.14 in your browser
Output
Run shows what your program prints. Check tests it on every example and the hidden tests.

More arithmetic exercises