- Problem: Calculating the volume of a cylinder.
A cylinder is the surface formed by the points at a fixed distance from a given straight line called the axis of the cylinder. It is one of the most basic geometric shapes.
In this lab, write a python program to calculate the volume of a cylinder with the radius and height entered by the user; note the volume of a acylinder is calculated using the formula shown in the figure.
- Here is the specification for the program:
Purpose:Calculate the volume of a cylinder
Preconditions:Input radius and height of a cylinder
Postconditions: Output the volume of the cylinder
- Design:
The following steps show the design (Pseudocode) of your program:
1. Get the length of the radius in inches from the user; make sure to use a descriptive
prompt so the user knows what to enter.
2. Get the height in inches; again, make sure to use a descriptive prompt so the user
knows what to enter.
3. Calculate the volume of a cylinder with the radius and height entered by the user;
note the volume of a sphere is calculated using the formula.
- Run Examples
When you have the program running correctly, Verify that your program produces the same output as in the following test cases.
--- Test case 1 ---
Welcome to Program 1
Enter the length of the radius for the cylinder:10.5
Enter the height in inches for the cylinder: 5
Volume of the cylinder is 1731.803
--- Test case 2 ---
Welcome to Program 1
Enter the length of the radius for the cylinder: 18
Enter the height in inches for the cylinder: 15
Volume of the cylinder is 15268.140
--- Test Case 3 ---
Welcome to Program 1
Enter the length of the radius for the cylinder:2
Enter the height in inches for the cylinder: 4
Volume of the cylinder is 50.265
- Requirments:
1- Use the built-in value for pi using math.pi
2- Your output should match the run examples above.
3- Make sure you document your program. Use good, multi-character, meaningful
identifiers (variables).
3- Show the result value of volume using three decimal values only as shown in the run examples.
4- At the top of your program, you should have a prolog (name, date, etc.) and comments explaining different operations in your code.
5- Save the program file as volume.py.
- When you are done, show your program to the Instructor and then submit your file (volume.py) as a submission for Lab 2 on CANVAS.