► Python program to calculate circumference of a circle
Steps followed:
1. take radius of circle as input from user
2. validate the input and then calculate the circumference of circle with formula 2*pi*r
3. print circumference
#python program to calculate circumference of a circle
#getting radius of circle as input from user
radius=input("Enter radius of circle: ")
try:
radius=float(radius)
#calculate circumference of circle
circumference = 2 * 22/7 * radius
#print circumference of circle
print("---output---")
print("circumference of circle with radius %0.2f is %0.2f"%(radius,circumference))
except:
print("---error---")
print("please enter a valid radius")
Enter radius of circle: 14
---output---
circumference of circle with radius 14.00 is 88.00
Enter radius of circle: python
---error---
please enter a valid radius