Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is Python Code. Can you rewrite it in different way than i have. Bascialy this program will calculate the cylinder, cube and sphere. I

This is Python Code. Can you rewrite it in different way than i have.

Bascialy this program will calculate the cylinder, cube and sphere. I have write the formula. we have to create the two files one uitlity modules to define all use-defined function for shape calculation. another we have to create a main application module that allows user to perform the required calculation. I have write the program code. can you rewrite in different way than i have write.

from math import pi

# # Functions for calculation of cylinder #

def CylVolume(radius, height): ''' This function calcuates and returns the volume of the cylinder

input radius - float height - float

Return volume - float

''' volume = pi*radius**2*height return volume

def CylLateral(radius, height): area = 2*pi*radius*height return area

def CylTopBot(radius, height): ''' This function calcuates and returns the area of top and bottom of the cylinder

input radius - float height - float

Return area - float

''' area = pi*radius**2 return area

def CylTotal(radius, height): ''' This function calcuates and returns the total surface area of the cylinder

input radius - float height - float

Return totalArea - float

''' totalArea = 2*pi*radius*(height + radius) return totalArea # # Functions for calculation of Cube #

def cubeVol(a): ''' This function calculates and return the volume of the cube input a - float return volume - float ''' vol = a**3 return vol

def cubeArea(a): ''' This function calculates and return the area of the cube input a - float return area - float ''' area = 6*a**2 return area

def cubeFace(a): ''' This function calculates and return the face diagonal of the cube input a - float return face diagonal - float ''' faceD = a*pi**3 return faceD # # Functions for calculation of Sphere #

def sphereVol(r): ''' This function calculates and returns the volume of the sphere input r - float Return volume - float ''' vol = (4/3)*pi*r**3 return vol

def sphereCircum(r): ''' This function calculates and returns the Circumference of the sphere input r - float Return circumference - float ''' circum = 2*pi*r return circum

def sphereArea(r): ''' This function calculates and returns the Surface area of the sphere input r - float Return area - float ''' area = 4*pi*r**2 return area

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

from utlity import * from os import system

while 1: print('Select a Geometric shape to perform calculations on :-') print('1 - Cylinder') print('2 - Cube') print('3 - Sphere') print() shape = int(input('>> ')) if shape not in [1,2,3]: print('Please make a valid selection') continue else: system('clear') # system('cls') if running in linux if shape == 1: while 1: userinput = input("Enter the radius of the cylinder : ") if userinput.isalpha(): print('Please enter number only ') else: break radius = float(userinput) while 1: userinput = input("Enter the height of the cylinder : ") if userinput.isalpha(): print('Please enter number only ') else: break height = float(userinput) while 1: print('Select what you want to calculate :- ') print('1 - Volume') print('2 - Lateral Surface Area') print('3 - Top and bottom surface area ') print('4 - Total surface area of closed cylinder ') while 1: calc = int(input()) if calc not in [1,2,3,4]: print('Please make a valid selection ') else: break if calc == 1: result = CylVolume(radius, height) print('Volume of the cylinder is : {}'.format(result)) elif calc == 2: result = CylLateral(radius, height) print('Lateral Surface area of cylinder is : {}'.format(result)) elif calc == 3: result = CylTopBot(radius, height) print('Top and Bottom surface area of the cylinder is : {}'.format(result)) elif calc == 4: result = CylTotal(radius, height) print('Total surface area of closed cylinder is : {}'.format(result)) more = input('Want to calculate more on this cylinder : (y/n)? : ') if more not in ['y','Y']: break elif shape == 2: while 1: userinput = input('Enter the length of the side of the cube : ') if userinput.isalpha(): print('Please enter numbers only') else: break a = float(userinput) while 1: print('Select what you want to calculate :- ') print('1 - Volume') print('2 - Surface Area') print('3 - Face diagonal of cube ') while 1: calc = int(input()) if calc not in [1,2,3]: print('Please make a valid selection ') else: break if calc == 1: result = cubeVol(a) print('Volume of the Cube is : {}'.format(result)) elif calc == 2: result = cubeArea(a) print('Area of Cube is : {}'.format(result)) elif calc == 3: result = cubeFace(a) print('Face diagonal of the cube is : {}'.format(result)) more = input('Want to calculate more on this Cube : (y/n)? : ') if more not in ['y','Y']: break

elif shape == 3: while 1: userinput = input('Enter the radius of the Sphere : ') if userinput.isalpha(): print('Please enter numbers only') else: break radius = float(userinput) while 1: print('Select what you want to calculate :- ') print('1 - Volume') print('2 - Circumference') print('3 - Surface area ') while 1: calc = int(input()) if calc not in [1,2,3]: print('Please make a valid selection ') else: break if calc == 1: result = sphereVol(radius) print('Volume of the Sphere is : {}'.format(result)) elif calc == 2: result = sphereCircum(radius) print('Circumference of Sphere is : {}'.format(result)) elif calc == 3: result = sphereArea(radius) print('Area of Sphere is : {}'.format(result)) more = input('Want to calculate more on this Sphere : (y/n)? : ') if more not in ['y','Y']: break system('clear') # system('cls') if running in linux again = input('Want to do more calculations on another figure : (y/n)? : ') if again not in ['y','Y']: print('Thanks for using the application')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions