► Python program to calculate area of a circle


Steps followed:
1. take radius of circle as input from user
2. validate the input and then calculate the area of circle with formula pi*r*r
3. print area


Program

#python program to calculate area of a circle

#getting radius of circle as input from user
radius=input("Enter radius of circle: ")

try:
    radius=float(radius)

    #calculate area of circle
    area = 22/7 * (radius**2)

    #print area of circle
    print("---output---")
    print("area of circle with radius %0.2f is %0.2f"%(radius,area))

except:
    print("please enter a valid radius")


Output

Enter radius of circle: 14
---output---
area of circle with radius 14.00 is 616.00

 

Enter radius of circle: circle
please enter a valid radius





Also Read: