Read a radius and print the area of the circle, math.pi * r * r, with two decimal places.
What to build
A program that uses a value from the math module.
Requirements
- Read the radius.
- Print the area with two decimal places, using
math.pi.
Input
One number r (a whole number or decimal) from 0 to 1000.
Output
The area with two decimal places.
Constraints
The radius is from 0 to 1000.
Example
Input:
3
Output:
28.27
Why it works
math.pi is far more accurate than typing 3.14, and the format code decides only how much of it is shown.
Examples
Example 1 · Input
3
Expected output
28.27
Example 2 · Input
1
Expected output
3.14
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
math.pi is about 3.14159.
Hint 2
f"{value:.2f}" shows two decimal places.
Solution
Show one correct solution (try it yourself first)
import math
r = float(input())
print(f"{math.pi * r * r:.2f}")