Last active
November 24, 2021 06:04
-
-
Save misterhtmlcss/04911e9c4fd5c2de8735c936986eee4f to your computer and use it in GitHub Desktop.
learning-journal-u2-a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
# 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this