Answer to Question #276410 in Python for solokin

Question #276410

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:

  • An explanation of each stage of development, including code and any test input and output.
  • The output of three calls to your function with different arguments.
1
Expert's answer
2021-12-06T14:05:06-0500
# 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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS