Write a program in python to take radius and height and print perimeter of circle and volume of cylinder .
Answers
Answered by
16
- ## I'll be defining 2 functions, i.e., perimeter_of_circle() and volume_of_cylinder().
- from math import pi ## I imported the value of pi from the inbuilt function, called math.
- ## You can also assign a variable with the value of pi.
- def perimeter_of_circle(): ## This function is defined for giving/printing the perimeter of the circle.
- perimeter = 2*pi*r ## This is the formula to find the perimeter of a circle.
- print("\nThe perimeter of the circle of the cylinder is {}.".format(round(perimeter,4))) # This will print the perimeter of the circle.
- def volume_of_cylinder(): ## This function is defined for giving/printing the volume of the cylinder.
- volume = pi * r**2 * h ## This is the formula to find the volume of a cylinder.
- print("\nThe volume of the cylinder is {}.".format(round(volume,4))) # This will print the volume of the cylinder.
- # Driver Code
- r = float(input("Type the value of the radius : ")) # The will make the user input the value of the radius.
- h = float(input("Type the value of the height : ")) # The will make the user input the value of the height.
- ## Calling the functions.
- perimeter_of_circle()
- volume_of_cylinder()
Attachments:
Answered by
17
The following codes must be typed in script mode, saved and then executed.
CODE:
r = float(input("Enter the radius of the circle:"))
pm=2*3.14*r
print("The perimeter of the circle is:", pm)
h = float(input("Enter the height of the cylinder:"))
rad = float(input("Enter the radius of the cylinder:"))
vol = 2*3.14*rad*h
print("The volume of the cylinder is", vol)
OUTPUT:
Attachments:
Similar questions