1. The surface area and volume of a sphere is defined to be: where r is the radius of the sphere. Write a program that asks the user to enter the name of two different types of spheres, such as a golf ball and basketball. Next, ask for radii of both balls. Report the volume and surface area of each ball in your program output.

Respuesta :

Answer:

Written in Python:

name1 = input("Name of Sphere 1: ")

r1 = float(input("Radius of "+str(name1)+": "))

name2 = input("Name of Sphere 2: ")

r2 = float(input("Radius of "+str(name2)+": "))

pi = 22.0/7.0

Volume1 = 4.0/3.0 * pi * r1**3

Volume2 = 4.0/3.0 * pi * r2**3

Area1 = 4.0 * pi * r1**2

Area2 = 4.0 * pi * r2**2

print("Volume of "+name1+": "+str(round(Volume1,2)))

print("Surface Area of "+name1+": "+str(round(Area1,2)))

print("Volume of "+name2+": "+str(round(Volume2,2)))

print("Surface Area of "+name2+": "+str(round(Area2,2)))

Explanation:

This line prompts user for name of first sphere

name1 = input("Name of Sphere 1: ")

This prompts user for radius of the first sphere

r1 = float(input("Radius of "+str(name1)+": "))

This line prompts user for name of second sphere

name2 = input("Name of Sphere 2: ")

This prompts user for radius of the second sphere

r2 = float(input("Radius of "+str(name2)+": "))

This initializes pi to 22/7

pi = 22.0/7.0

The next two lines calculate the volumes of each sphere

Volume1 = 4.0/3.0 * pi * r1**3

Volume2 = 4.0/3.0 * pi * r2**3

The next two lines calculate the areas of each sphere

Area1 = 4.0 * pi * r1**2

Area2 = 4.0 * pi * r2**2

The next two lines print the volume and area of the first sphere

print("Volume of "+name1+": "+str(round(Volume1,2)))

print("Surface Area of "+name1+": "+str(round(Area1,2)))

The next two lines print the volume and area of the second sphere

print("Volume of "+name2+": "+str(round(Volume2,2)))

print("Surface Area of "+name2+": "+str(round(Area2,2)))