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
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.
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:...
Write a python program for the following question. Complete the symptom similarity function, which measures the...
Write a python program for the following question. Complete the symptom similarity function, which measures the similarity between the symptoms of two patients. See below for an explanation of how the similarity is computed. def symptom_similarity(symptoms_A: Tuple[Set], symptoms_B: Tuple[Set]) -> int: '''Returns the similarity between symptoms_A and symptoms_B. symptoms_A and symptoms_B are tuples of a set of symptoms present and a set of symptoms absent. The similarity measure is computed by the following equations: present_present + absent_absent - present_absent -...
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 program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
You want to write a simple python program for a food delivery company that asks the...
You want to write a simple python program for a food delivery company that asks the office worker how many drivers they require to deliver their packages to different parts of town. When the user enters the number of drivers, the program will ask how many packages each driver will carry to its destination. It will then calculate the total number of packages and display the result on the screen as below. Sample run: How many drivers do you need?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT