Part 2
Invent your own function that does some useful computation of your choosing. Do not copy the function from somewhere else. Use incremental development, and record each stage of the development process as you go. Finally, print output that demonstrates that the function works as you intended.
Include all of the following in your Learning Journal:
# Python 3.9.5
import math # Library for displaying pi
def get_cylinder_volume(r, h): # Function declaration
r = int(r) # Change the format of the
h = int(h) # variables from str to int
if r > 0 and h > 0: # Сhecking the input of valid data
V = h*r*math.pi # Сalculating the volume of the cylinder
print('Volume of cylinder: ', round(V, 2)) # Displaying result
else:
print('Invalid data was entered, please try again!') # Message in case of incorrect input
r, h = input('Enter a space-separated value for the radius and height: ').split() # Enter data
get_cylinder_volume(r, h) # Function call
# The function can be checked with any positive numbers
Comments
Leave a comment