Question

In: Computer Science

1) Write a simple python function program that can calculate the volumes of following shape: cylinder,...

1) Write a simple python function program that can calculate the volumes of following shape: cylinder, circle, cone and sphere. For each of this shape, write a separate function. Let your function take in 2 inputs only. Your program should prompt user to enter these 2 inputs and print out the results of the volumes of the shape separately?

Solutions

Expert Solution

Circle does not have volume as it is 2 dimensional figure it only has area and circumference.

CODE-

#Function for calculating cylinder volume
def vol_cylinder(height,radius):
pi=22/7
global volume_cyl
volume_cyl = pi * radius * radius * height
  
#Function for calculating circle area
def area_circle(radius):
pi=22/7
global area
area = pi * radius * radius
  
#Function for calculating cone volume
def vol_cone(height,radius):
pi=22/7
global volume_cone
volume_cone = (pi * radius * radius * height)/3
  
#Function for calculating sphere volume
def vol_sphere(radius):
pi=22/7
global volume_sphere
volume_sphere = (4 * pi * radius * radius * radius)/3

#taking user input for height and radius of cylinder   
height = float(input('Enter Height of cylinder: '))
radius = float(input('Enter Radius of cylinder: '))
vol_cylinder(height,radius)

#taking user input for radius of circle
print("=======================================")
radius = float(input('Enter Radius of circle: '))
area_circle(radius)

#taking user input for height and radius of cone
print("=======================================")
height = float(input('Enter Height of cone: '))
radius = float(input('Enter Radius of cone: '))
vol_cone(height,radius)

#taking user input for height and radius of sphere
print("=======================================")
radius = float(input('Enter Radius of sphere: '))
vol_sphere(radius)

#Printing all volumes separately
print("\nVolume of cylinder is: ", volume_cyl)
print("Area of circle is: ", area)
print("Volume of cone is: ", volume_cone)
print("Volume of sphere is: ", volume_sphere)

Output-


Related Solutions

Write a Python program which uses a function to calculate the perimeter of a rectangle. a...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a function named volume to calculate the volume of a cylinder volume = 3.14 x radius x radius x height .b function named volume to calculate the volume of a cuboid volume = Length x width x ht Write a Python Program to calculate the sum of all odd numbers for 2 to 20 using a for loop. 4. Write statements that assign random integers...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
Program in Python Problem Statement Write a program with the following functions:  wordCount. This function...
Program in Python Problem Statement Write a program with the following functions:  wordCount. This function should accept a string as a parameter and return the number of words contained in the string.  mostFrequentWord. This function accepts a string as a parameter and returns the word that occurs the most frequently in the string.  replaceWord. This function accepts three strings as parameters, let’s call them string1, string2, and string3. It searches string1 for all occurrences of string2. When...
Can someone do this python program? Write a function that takes a number as a parameter...
Can someone do this python program? Write a function that takes a number as a parameter and then prints out all of the factors for that number.
In simple python code 1) Write a function to convert the image to grayscale. 2Write a...
In simple python code 1) Write a function to convert the image to grayscale. 2Write a function to convert an image to black and white 3)Sepia Tone images are those brownish colored images that may remind you of times past. The formula for creating a sepia tone is as follows: newR = (R × 0.393 + G × 0.769 + B × 0.189) newG = (R × 0.349 + G × 0.686 + B × 0.168) newB = (R ×...
Write a simple Python program that will generate two random between 1 and 6 ( 1...
Write a simple Python program that will generate two random between 1 and 6 ( 1 and 6 are included). If the sum of the number is grader or equal to 10 programs will display “ YOU WON!!!”. if the sum is less than 10, it will display “YOU LOST”. After this massage program will ask users a question: “if you want to play again enter Y. if you want to exit enter ‘N’) If the user enters Y they...
Write a simple Python program that will generate two random between 1 and 6 ( 1...
Write a simple Python program that will generate two random between 1 and 6 ( 1 and 6 are included). If the sum of the number is grader or equal to 10 programs will display “ YOU WON!!!”. if the sum is less than 10, it will display “YOU LOST”. After this massage program will ask users a question: “if you want to play again enter Y. if you want to exit enter ‘N’) If the user enters Y they...
Need this in C# Write a simple lottery program which can do the following: 1. asks...
Need this in C# Write a simple lottery program which can do the following: 1. asks the user to provide an integer value from 1 to 5 2. generates one random integer number from 1 to 5 3. display “You lost $1” if the two numbers are different, and display “You won $5” otherwise.the program asks if the user wants to continue playing the lottery. If yes, the program repeats steps 1-3. If no, the program terminates.
Write a python function (Without using external libraries) to calculate the 1). determinate of a 2...
Write a python function (Without using external libraries) to calculate the 1). determinate of a 2 x 2 matrix 2). Calculate the inverse of a 2 x 2 matrix.
Write a Python program that uses function(s) for the following problem: A nutritionist who works for...
Write a Python program that uses function(s) for the following problem: A nutritionist who works for a fitness club helps members by evaluating their diets. As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consumed in a day (two inputs, one for number of fat grams and the other for number of carb grams). Then, she calculates the number of calories that result from the fat, using the following formula:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT