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.
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)
Comments
Leave a comment