Skip to content

Instantly share code, notes, and snippets.

@misterhtmlcss
Last active November 24, 2021 06:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterhtmlcss/04911e9c4fd5c2de8735c936986eee4f to your computer and use it in GitHub Desktop.
Save misterhtmlcss/04911e9c4fd5c2de8735c936986eee4f to your computer and use it in GitHub Desktop.
learning-journal-u2-a
"""
# Part 1
The volume of a sphere is 4/3πr3, where π has the value of "pi" given in Section 2.1 of your textbook. Write a function called print_volume (r) that takes an argument for the radius of the sphere, and prints the volume of the sphere.
✓ Call your print_volume function three times with different values for radius.
✓ Include all of the following in your Learning Journal:
- The code for your print_volume function.
- The inputs and outputs to three calls of your print_volume.
"""
# Module import
import math
# I could have manually assigned as in the book, but I elected to do it this way.
my_pi = math.pi
def print_volume (r):
# formula - 4/3πr3
result = 4 / 3 * my_pi * r * 3
return result
# Call your print_volume function three times with different values for radius.
print('print_volume(10): volume of the sphere', print_volume(10))
print('print_volume(20): volume of the sphere', print_volume(20))
print('print_volume(30): volume of the sphere', print_volume(30))
# OUTPUT
# print_volume(10): volume of the sphere 125.66370614359171
# print_volume(20): volume of the sphere 251.32741228718342
# print_volume(30): volume of the sphere 376.99111843077515
@JoyNgaru
Copy link

Thank you for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment