$24
Learning Outcome:
By completing this assignment, you will gain skills relating to
using loops,
using functions,
and using lists in Python.
Task:
In this assignment, you will write a complete program in Python that computes the volume for a series of shapes. Your program is expected to prompt the user for input and validate it before computing the volume. In addition, your program should keep track of each volume that is calculated and at the end display the volume for all the shapes. Your program should make use of functions, loops, and lists.
Functional Specifications:
Your program should first ask the user for the shape they are interested in, check to make sure that their input is valid, if the input is not valid, keep on asking them until valid input is given. Valid input options are: “cube”, “pyramid”, “ellipsoid”, “quit”
Based on their selection, prompt them for the necessary dimensions, it is safe to assume that the user enters positive numeric values.
Next your program should calculate the volume for the specified shape given the dimensions and display the volume to the screen. Your program should also store the volume.
Shape
Volume
cube
= 3 where a is the length of a side
pyramid
=
1
2ℎ
where b is base length and h is height
3
ellipsoid
=
4
∗
∗
∗ where pi is π and r is used to represent
3
1
2
3
each radius
Sample output
The volume of a pyramid with a base of 10 and height of 12 is 40.0
Your program should continue to compute volumes as specified by the user until the user enters “quit”. At this point in time, your program should print the volumes based on their shape and in ascending order.
Sample final output
You have come to the end of the session.
The volumes calculated for each shape are shown below
Cube: 8.0, 27.0, 34.3, 40.0, 64.0
Pyramid: 10.0, 29.4, 102.0
Ellipsoid: 3.1, 12.6, 31.4
If the user enters quit option before actually calculating any volumes show the output below.
You have come to the end of the session.
You did not perform any volume calculations.
In order to develop modular code, you MUST encapsulate the prompting for input and calculation of volume for each shape within a function. That is, you MUST have at least 3 functions, one for cube, another for pyramid, and a third for ellipsoid.
The volumes should be formatted to 1 decimal place.
Non-functional Specifications:
Include brief comments in your code identifying yourself, describing the program, and describing key portions of the code.
Assignments are to be done individually and must be your own work. Software may be used to detect cheating.
Use Python coding conventions and good programming techniques, for example: Meaningful variable and function names
Conventions for naming variables and constants Use of constants where appropriate
Readability: indentation, white space, consistency
The name of the file you submit should be your UWO userid_Assign2.py. For instance, my assignment would be oola_Assign2.py. Make sure you attach your python file to your assignment; DO NOT put the code inline in the textbox.
Make sure that you develop your code with Python 3.5 as the interpreter. TAs will not endeavor to fix code that uses earlier versions of Python.
What You Will Be Marked On:
Functional specifications:
Does the program behave according to specifications? Does the program handle invalid input?