Exercises for Lesson 10

Back to Lesson 10

Exercise 1: Max of n

Extend our maxOfThree function to compute the maximum number in a list.

def maxOfList(numList):
    """
    Returns the maximum number in the given list.
    Assumes the list contains only numbers.
    """
    pass # replace with your code

Exercise 2: More practice with conditionals

Further extend your maxOfList function to ask the user for numbers instead of taking in a list.

def maxOfN():
    """
    Asks the user for a series of numbers and returns the largest.

    Returns: the largest of the numbers the user enters
    """
    pass # replace with your code

Part a: use a for loop

Ask the user for n and then ask for each of the n values in a for loop.

Part b: use a while loop

Read ahead about while loops in Zelle sections 8.1-8.3.2 (pp. 243-252).

Then, change your maxOfN function to instead ask the user to enter numbers one at a time (rather than entering n first) or to enter nothing (just press enter, giving an empty string "") to quit.

Back to Lesson 10