In: Computer Science
For this assignment, you will write a program that consists of four function definitions, including one main() function. The main function gets inputs from the user, and the other functions show output to the user. When the program is executed, it asks the user to enter a small amount of information, and then shows output based on the user's info.
Specification:
Here are some specific requirements for this program:
A circle with a radius of __ cm has a diameter of __ cm, a circumference of __ cm and an area of __ cm^2.
A solid sphere with a radius of __ cm and a density of __ g/cm^3 has a surface area of __ cm^2, a volume of __ cm^3 and a mass of __ g.
A solid cylinder with a radius of __ cm, a length of __ cm and a density of __ g/cm^3 has a surface area of __ cm^2, a volume of __ cm^3 and a mass of __ g.
>>> Enter the desired radius (in cm): 2.1 Enter the desired length (in cm): 3.75 Enter the desired density (in g/cm^3): 5 Here are results for your specified characteristics: A circle with a radius of 2.10 cm has a diameter of 4.20 cm, a circumference of 13.19 cm and an area of 13.9 cm^2. A solid sphere with a radius of 2.10 cm and a density of 5.0 g/cm^3 has a surface area of 55.4 cm^2, a volume of 38.8 cm^3 and a mass of 194 g. A solid cylinder with a radius of 2.10 cm, a length of 3.75 cm and a density of 5.0 g/cm^3 has a surface area of 77.2 cm^2, a volume of 52.0 cm^3 and a mass of 260 g. Here are results when the radius is doubled: A circle with a radius of 4.20 cm has a diameter of 8.40 cm, a circumference of 26.39 cm and an area of 55.4 cm^2. A solid sphere with a radius of 4.20 cm and a density of 5.0 g/cm^3 has a surface area of 221.7 cm^2, a volume of 310.3 cm^3 and a mass of 1552 g. A solid cylinder with a radius of 4.20 cm, a length of 3.75 cm and a density of 5.0 g/cm^3 has a surface area of 209.8 cm^2, a volume of 207.8 cm^3 and a mass of 1039 g. If the sphere and cylinder you specified were made of solid gold, these would be the results: A solid sphere with a radius of 2.10 cm and a density of 19.3 g/cm^3 has a surface area of 55.4 cm^2, a volume of 38.8 cm^3 and a mass of 749 g. A solid cylinder with a radius of 2.10 cm, a length of 3.75 cm and a density of 19.3 g/cm^3 has a surface area of 77.2 cm^2, a volume of 52.0 cm^3 and a mass of 1003 g.
TIPS:
Documentation and Style:
Program Submission: Upload a single .py file using the tool on this page.
// python
// if you have any doubt let me know i will try to help you. Thank you.
import math
def show_circle_info(radius):
diameter=2*radius
pi=math.pi
circum=2*pi*radius
area=pi*radius*radius
print('A circle with a radius of ',round(radius,2),' cm has a diameter of ',round(diameter,2),' cm,')
print('a circumference of ',round(circum,2),' cm and an area of ',round(area,1),'cm^2.')
print()
def show_sphere_info(radius,density):
surface_area=4*math.pi*radius*radius
volume=(4/3)*math.pi*math.pow(radius,3)
mass=density*volume
print('A solid sphere with a radius of ',round(radius,2),' cm and a density of ',round(density,2),' g/cm^3')
print('has a surface area of ',round(surface_area,1),' cm^2, a volume of ',round(volume,1),' cm^3 and a mass of ',math.ceil(mass),'g.')
print()
def show_cylinder_info(radius,length,density):
pi=math.pi
surface_area=(2*pi*radius*length) +(2*pi*radius*radius)
volume=pi*radius*radius*length
mass=density*volume
print('A solid cylinder with a radius of ',round(radius,2),' cm, a length of ',round(length,2),'cm and a density of ',round(density,2),' g/cm^3 ')
print('has a surface area of ',round(surface_area,1),' cm^2, a volume of ',round(volume,1),' cm^3 and a mass of ',math.ceil(mass),'g.')
print()
def main():
radius=float(input("Enter the desired radius (in cm): "))
length=float(input("Enter the desired length (in cm): "))
density=float(input("Enter the desired density (in g/cm^3): "))
show_circle_info(radius)
show_sphere_info(radius,density)
show_cylinder_info(radius,length,density)
if __name__=="__main__":
main()
// Sample output:-