Introduction:
This code defines a Python function that calculates the area and circumference of a circle. It takes the radius as input and returns a tuple containing the area and circumference. The user is prompted to enter the radius and the results are displayed on the console.
Code:
#Function to compute area and circumference of the circle.
def circle(r):
area = 3.14*r*r
circumference = 2*3.14*r
#returns a tuple having two elements area and circumference
return (area,circumference)
#end of function
radius = int(input('Enter radius of circle: '))
area,circumference = circle(radius)
print('Area of circle is:',area)
print('Circumference of circle is:',circumference)
Logic:
- Define the function “circle” that takes the radius as an argument.
- Calculate the area using the formula: area = 3.14 * r * r.
- Calculate the circumference using the formula: circumference = 2 * 3.14 * r.
- Return a tuple containing the area and circumference.
- Prompt the user to enter the radius.
- Call the function circle with the entered radius and store the returned values in the variables area and circumference.
- Print the calculated area and circumference on the console.
Output:
Enter radius of circle: 4
>> Area of circle is: 50.24
>> Circumference of circle is: 25.12