Python Programming – John Zelle: Chapter 3 ex. 1

Write a program to calculate the volume and surface area of a sphere from it’s radius, given it’s input.

I modified the exercise to indicate the units of mesaure.

Chapter 3 Exercise 1

Python

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #Chapter 3 Exercise 1 #Write a program to calculate the volume and surface area of a sphere from it’s radius, given it’s input. from math import * def main(): print("This program finds the volume and surface area of a sphere") r = eval(input("Please enter the radius of the sphere in cm: ")) area = (4 * pi * r**2) volume = ((4 * pi * r**3) / 3) print() print("The volume of the sphere is", volume, "cubic cm",) print("The area of the sphere is", area, "square cm") main() |

Run =

This program finds the volume and surface area of a sphere

Please enter the radius of the sphere in cm: 30

The volume of the sphere is 113097.33552923256 cubic cm

The area of the sphere is 11309.733552923255 square cm