Question: Write a function that determines a maximum value from a variable number of arguments. The function is described below. Requirements: 1) Use the maxOfTwo function

Write a function that determines a maximum value from a variable number of arguments. The function is described below. Requirements:

1) Use the maxOfTwo function you wrote for Lab #C. That maxOfTwo function takes two parameters and returns the greater of the two.

2) The new function maxOf should take any number of parameters and return the largest of them. It should call maxOfTwo as many times as required.

3) Setup your code to use print to write out the results of these calls:

a) maxOf( 24, 10 ) b) maxOf( 102, 12, 4, 101 ) c) maxOf( 6, 7, 8, 9, 10 ) d) maxOf( ?6, 7, 345, 9, ?400 )

#Lab C code

def maxOfTwo(n1, n2): if n1 > n2: return n1 else: return n2

def maxOfThree(n1, n2, n3): m = maxOfTwo(n1, n2) return maxOfTwo(m, n3)

print(maxOfTwo(5, 7)) print(maxOfTwo(105, 7)) print(maxOfTwo("yes", "no")) print(maxOfThree(8, 16, 1)) print(maxOfThree(28, 16, 1)) print(maxOfThree(28, 16, 106)) print(maxOfTwo(False, 0)) print(maxOfTwo(0, False))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!