Solution 1.
from math import pi
radius = float(input("Enter radius of the circle : "))
calculated_area = (pi * radius**2)
print("The area of the circle with radius",radius,"is",calculated_area)
Output :
Enter radius of the circle : 7
The area of the circle with radius 7.0 is 153.93804002589985
What if we used 22/7 (fraction value of pi) instead of pi…
radius = float(input("Enter radius of the circle : "))
calculated_area = (22/7 * radius**2)
print("The area of the circle with radius",radius,"is",calculated_area)
Output :
Enter radius of the circle : 7
The area of the circle with radius 7.0 is 154.0
Solution 2 :
# Take input from user
width = float(input("Width of the rectangle : "))
height = float(input("Height of the rectangle : "))
#calculate Area
area = width * height
print("Area is",width,"x",height,"=",area)
#calculate perimeter
perimeter = 2 * (width + height)
print("Perimeter is 2 x (",width,"+",height,") =",perimeter)
Output :
Width of the rectangle : 10.5
Height of the rectangle : 7.5
Area is 10.5 x 7.5 = 78.75
Perimeter is 2 x( 10.5 + 7.5 ) = 36.0