InLab04

py

School

Purdue University *

*We aren’t endorsed by this school

Course

15501

Subject

Computer Science

Date

Dec 6, 2023

Type

py

Pages

2

Uploaded by CoachWillpowerRaven49

Report
#=============================================================== # Your Name & Lab Section: Matas Andrikonis, Thursday 3:30PM # Your Purdue Email: mandriko@purdue.edu # Program Description: I had the user input a value that was supposed to be between 1-3 and if it wasn't they would get a message saying that it # does not meet the range, if they did pick between 1 and 3 then they would have to enter certain values and with those values I would give them # the volume of either a spere, hexagonal pyramid, or octagonal prism, depending on what number between 1 and 3 they chose # Academic Honesty: # I attest that this is my original work. # I have not used unauthorized source code, either modified or #unmodified. # I have not given other fellow student(s) access to my program. #================================================================= import math def main(): print(" Volume Calculator") print("=======================================================================") print("1. Volume of a Sphere") print("2. Volume of a Hexagonal Pyramid") print("3. Volume of an Octagonal Prism") print("=======================================================================") print("") eq = int(input("Choose one of the options to calculate: ")) #this is where the user inputs which equation they want print(eq) print("") if (eq == 1): #if statement for the value they input print("Option 1. Volume of a Sphere") print("") rad = int(input("Enter the radius of the sphere: ")) #user inputs radius print("") sphvol = (4/3)*(math.pi*pow(rad, 3)) #equation for the volume of a sphere print(f"The volume of the Sphere is {sphvol:.2f}") #final output and the volume of the sphere rounded to two decimal places elif(eq == 2): #if statement for the value they input print("Option 2. Volume of Hexagonal Pyramid") print("") base = float(input("Enter the base edge of the Hexagonal Pyramid: ")) #user inputs base edge height = float(input("Enter the height of the Hexagonal Pyramid: ")) #user inputs the height print("") hexvol = (math.sqrt(3)/2)*pow(base,2)*height #equation for volume of hexagonal pyramid print(f"The volume of the Hexagonal Pyramid is {hexvol:.2f}") #final output and the volume of a hexagonal pyramid rounded to two decimals elif(eq == 3): #if statement for the value they input print("Option 3. Volume of an Octagonal Prism") print("") bedge = float(input("Enter the base edge of the Octagonal Prism: ")) #user inputs base edge oheight = float(input("Enter the height of the Octagonal Prism: ")) #user inputs height print("") octvol = 2*(1 + math.sqrt(2))*pow(bedge,2)*oheight #equation for the volume
of a Octagonal Prism print(f"The volume of the Octagonal Prism is {octvol:.2f}") #final output and the volume of a octagonal prism rounded to two decimals else: #if user input is outside of 1-3 they will get this message indicating for them to select a number between 1 and 3 print("Invalid Input!") print("Please enter your choice between 1-3.") main()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help