Answer to Question #165757 in Python for Paul Carpenter

Question #165757

Part 1


As an exercise, use incremental development to write a function called hypotenuse that returns the length of the hypotenuse of a right triangle given the lengths of the other two legs as arguments. Record each stage of the development process as you go. (Downey, 2015)


After the final stage of development, print the output of hypotenuse(3, 4) and two other calls to hypotenuse with different arguments.


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 hypotenuse(3,4).

The output of two additional calls to hypotenuse with different arguments.


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-02-23T04:03:42-0500
import math
def hypotenuse(x, y):
    return math.sqrt(x ** 2 + y ** 2)
#testing 1
print ("The hypotaneous of the triangle will be:",hypotenuse(3, 4))
#testing 2
print ("The hypotanesous of the triangle will be ",hypotenuse(12, 5))

6.2 (part 2)
def SumAndRange(array,a,b):
    # conversion of the entered string into integer
   a=int(a)
   b=int(b)
   sum=0
    #casting of string into integer from array
   for i in array:
       i=int(i)
       if i>=a and i<=b:
           sum=sum+i
   print("The sum of the numbers between range",end=" ")
   print(a,end=" and ")
   print(b,end=" is ")
   print(sum)

array=[4,5,6,7,8,9,10]
a=3
b=6
SumAndRange(array,a,b)
a=6
b=8
SumAndRange(array,a,b)
a=5
b=10
SumAndRange(array,a,b)

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