CPSC120
Fundamentals of Computer Science

In-class Activity 19

  1. Create a Python program that computes the maximum of a collection of numbers. The program should prompt the user to enter a positive integer for the number of numbers to be input by the user. Then the program should repeatedly prompt the user to enter each number, one at a time. Once all of the numbers have been entered the program should print the maximum. Do not use the built-in max function.

  2. What would the following snippet of Python code print if run?

    spam = [1, 2, 3, 4, 5]
    print(spam[0:3])
  3. What would the following snippet of Python code print if run?

    spam = []
    for i in range(1, 6):
        spam.append(i)
    print(spam[:3])
  4. What would the following snippet of Python code print if run?

    spam = list(range(1, 6))
    print(spam)
  5. Create a Python program that computes the average of a collections of numbers. The program should prompt the user to enter a comma separated list of numbers and then print the average.