Question

Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such...

Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such as a cube, sphere, cylinder and cone.

In this file there should be four methods defined.

  • Write a method named cubeVolFirstName, which accepts the side of a cube in inches as an argument into the function. The method should calculate the volume of a cube in cubic inches and return the volume. The formula for calculating the volume of a cube is given below.
  • Write a method named sphereVolFirstName, which accepts the radius of a sphere in inches as an argument into the function. The method should calculate the volume of a sphere in cubic inches and return the volume. The formula for calculating the volume of a sphere is given below.
  • Write a method named cylVolFirstName, which accepts the radius of a cylinder and height of the cylinder in inches as arguments into the function. The method should calculate the volume of a cylinder in cubic inches and return the volume. The formula for calculating the volume of a cylinder is given below.
  • Write a method named coneVolFirstName, which accepts the radius of a cone and height of the cone in inches as arguments into the function. The method should calculate the volume of a cone in cubic inches and return the volume. The formula for calculating the volume of a cone is given below.
  • You don’t have to define a main in this program.

Now Write a Python program named LastNameMenu that asks the user to find volumes of 3D objects. The program will then present the following menu of selections:

  1. Volume of a cube in cubic inches.
  2. Volume of a sphere in cubic inches.
  3. Volume of a cylinder in cubic inches.
  4. Volume of a cone in cubic inches.
  5. Exit the program

  • This program should import lastNameVolume and should be able to use the functions from that file.
  • Write a void method named menuFirstName that displays the menu of selections. This method should not accept any arguments.
  • The program should continue to display the menu until the user enters 5 to quit the program.
  • If the user selects an invalid choice from the menu, the program should display an error message.
  • Based on the option entered, corresponding volume function from the other file is invoked and the volume is displayed by the Menu program.
  • For example if option 1 is entered, the menu program should ask for the side of the cube in inches
    • Make sure that the input is a positive number greater than 0.
    • Write one validInput program in the Menu file which returns True if the input is valid.
    • This function can be reused for all inputs.
    • Once the input is validated, it calls the cubeVolFirstName function in the other file which returns the volume.
    • The volume is displayed. Format the volume output to two decimals
  • As usual submit the two files in the form of a zip file
  • Add comments to show what each function does.

Here are the formula used for volume calculation:

Volume of a cube with side a = a3

Volume of a sphere with radius r =4/3 π r3

Volume of a cylinder with radius r and height h = π r2 h

Volume of a cone with radius r and height h = 1/3 π r2 h

Here is an example session with the program, using console input. The user’s input is shown in bold.

MENU

  1. Volume of a cube in cubic inches.
  2. Volume of a sphere in cubic inches.
  3. Volume of a cylinder in cubic inches.
  4. Volume of a cone in cubic inches.
  5. Exit the program

Enter your choice: 1 [Enter]

We are going to calculate the volume of a cube.

Please enter the side of a cube in inches: 10 [Enter]

Volume of the cube with side 10 inches is: 1000.00 cubic inches.

MENU

  1. Volume of a cube in cubic inches.
  2. Volume of a sphere in cubic inches.
  3. Volume of a cylinder in cubic inches.
  4. Volume of a cone in cubic inches.
  5. Exit the program

Enter your choice: 3 [Enter]

We are going to calculate the volume of a cylinder.

Please enter the radius of a cylinder in inches: 2.5 [Enter]

Please enter the height of a cylinder in inches: 6 [Enter]

Volume of the Cylinder with radius 2.5 inches and height 6 inches is: 117.81 cubic inches.

MENU

  1. Volume of a cube in cubic inches.
  2. Volume of a sphere in cubic inches.
  3. Volume of a cylinder in cubic inches.
  4. Volume of a cone in cubic inches.
  5. Exit the program

Enter your choice: 5 [Enter]

Bye!

Homework Answers

Answer #1

THIS IS THE CODE OF THE FILE  LastNameMenu.py .

from lastNameVolumes import *
def menuFirstName():
    print("MENU\n")
    print("Volume of a cube in cubic inches.\n")
    print("Volume of a sphere in cubic inches.\n")
    print("Volume of a cylinder in cubic inches.\n")
    print("Volume of a cone in cubic inches.\n")
    print("Exit the program\n")

def validate(r,h):
    if r>0 and h>0:
        return True
    else:
        return False
    
def validate2(s):
    if s>0:
        return True
    else:
        return False

menuFirstName()
while True:
    a=int(input("Enter your choice:\n"))

    if a==1:
        print("We are going to calculate the volume of a cube.\n")
        b=float(input("Please enter the side of a cube in inches:\n"))
        c=validate2(b)
        if c==1:
            e=cubeVolFirstName(b)
            print("Volume of the cube with side " + str(b) + " inches is: " + str(e) + " cubic inches.\n")
        menuFirstName()
        
        
    elif a==2:
        print("We are going to calculate the volume of a sphere.\n")
        b=float(input("Please enter the radius of a sphere in inches:\n"))
        c=validate2(b)
        if c==1:
            print("Volume of the sphere with radius " + str(b) + " inches is: " + str(sphereVolFirstName(b)) + " cubic inches.\n")
        menuFirstName()
        
    elif a==3:
        print("We are going to calculate the volume of a cylinder.\n")
        b=float(input("Please enter the radius of a cylinder in inches:\n"))
        d=float(input("Please enter the height of a cylinder in inches:\n"))
        c=validate(b,d)
        if c==1:
            print("Volume of the cylinder with radius " + str(b) + "and height " + str(d) + "inches is: " + str(cylVolFirstName(b,d)) + " cubic inches.\n")
        menuFirstName()
        
    elif a==4:
        print("We are going to calculate the volume of a cone.\n")
        b=float(input("Please enter the radius of a cone in inches:\n"))
        d=float(input("Please enter the height of a cone in inches:\n"))
        c=validate(b,d)
        if c==1:
            print("Volume of the cone with radius " + str(b) + " and height " + str(d) + " inches is: " + str(coneVolFirstName(b,d)) + " cubic inches.\n")
        menuFirstName()
        
    elif a==5:
        print("Bye!")
        exit()
    else:
        print("ERROR !!! Enter correct value\n")
        menuFirstName()
        

THIS IS THE CODE OF THE FILE lastNameVolumes.py

def cubeVolFirstName(side):
    return round((side*side*side),2)
def sphereVolFirstName(radius):
    return round(((4*3.14*radius*radius*radius)/3),2)
def cylVolFirstName(radius,height):
    return round((3.14*radius*radius*height),2)
def coneVolFirstName(radius,height):
    return round(((3.14*radius*radius*height)/3),2)

HOPE IT HELPS YOU :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Question 1 Write a program that reads from the user the height and radius of a...
Question 1 Write a program that reads from the user the height and radius of a cylinder, and then outputs the area of this cylinder. The area of the cylinder is calculated using the formula: A=2*π*r*h+2*π*r2, where π = 3.14. Sample run: Enter the radius of the cylinder: 8.2 Enter the height of the cylinder: 9 The area of the cylinder is 885.75 Question 2 Write a program that reads the name, weight and height of a patient. Then the...
Write a Python program to calculate the area of a circle. The user needs to input...
Write a Python program to calculate the area of a circle. The user needs to input the value of the radius of the circle. area = 3.14 x radius x radius You should use a function named circlearea to perform the calculation 3. Write a Python program to calculate the area of a square. The user needs to input the value of the length of the square. area = len*len You should use a function named squarearea to perform the...
Write a program that reads a file named input.txt and writes a file that contains the...
Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line...
Write a method named generateHashtag that accepts a Scanner object as its parameter – your program...
Write a method named generateHashtag that accepts a Scanner object as its parameter – your program should continuously read phrase (a line of input - can contain spaces) using the nextLine() method of the Scanner class until the String read in equals “done” (ignoring case). For each phrase entered, your method should print a hashtag (#) followed by the phrase with spaces removed and all letters lowercase.
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
complete a C++ program that asks the user to make a choice off a menu that...
complete a C++ program that asks the user to make a choice off a menu that will be displayed to them. The user can make as many selections as they wish. The last choice from the menu will give them an option to stop. The menu choices will be the following four calculations: Find the volume of a cone Find the volume of a sphere Find the area of octagon Find the distance between two points Stop For the different...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Program Description A local company has requested a program to calculate the cost of different hot...
Program Description A local company has requested a program to calculate the cost of different hot tubs that it sells. Use the following instructions to code the program: File 1 - HotTubLastname.java Write a class that will hold fields for the following: The model of the hot tub The hot tub’s feature package (can be Basic or Premium) The hot tub’s length (in inches) The hot tub’s width (in inches) The hot tub’s depth (in inches) The class should also...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with four items. The user should then be prompted to make a selection from the menu and based on their selection the program will perform the selected procedure. The title and menu should be as the following: Student name: <your name should be printed> CIS 232 Introduction to Programming Programming Project 6 Due Date: October 23, 2020 Instructor: Dr. Lomako ******************************** 1.     Compute Angles                               *...