Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a python program that calculates the volume of a cylinder. Your program sh

ID: 3855089 • Letter: W

Question

Write a python program that calculates the volume of a cylinder. Your program should ask the user to enter the radius and the height of the cylinder. Your program will use the formula x r2 x h where = 3.14159, r = the radius of the cylinder and h = the height of the cylinder. Your program should include an input function, a processing function and an output function in addition to your main function. Do not forget to include the unit of measurement you are using in the output function. Format the response to the hundredth position. Provide meaningful comments in your code to let other coders know what your intentions are for each function.

Explanation / Answer



If you want to go with the functional approach to calculate volume of cylinder as required in the question then you can try this approach-

import math

def volume_of_cylindar(radius, height):           # defined a function to calculate volume

volume = math.pi * radius * radius * height     # math.pi provides value 3.14159

return volume

radius = int(input("Radius of cylinder:"))          #enter radius

height = int(input("Height of the cylinder:"))     # enter height

print(volume_of_cylind](radius,height))            # call the function

If you want to make your code simple then you can go with the following approach-

PI = 3.14159

radius = float(input('Please Provide Radius of a Cylinder: '))       #enter radius

height = float(input('Please Provide Height of a Cylinder: '))        # enter height

Vol = PI * radius * radius * height                                                  # your volume

print(" The Volume of a Cylinder = %.2f" %Vol)                            # print volume

Thanking you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote