CPSC120
Fundamentals of Computer Science

In-class Activity 20

  1. Create a Python program that computes the median of a collections of numbers. The program should prompt the user to enter a comma separated list of numbers and then print the median.

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

    def edit(integer):
        integer = 0
    
    spam = 1
    edit(spam)
    print(spam)
  3. What would the following snippet of Python code print if run?

    def edit(string):
        string = string + " zero"
    
    spam = "one"
    edit(spam)
    print(spam)
  4. What would the following snippet of Python code print if run?

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

    def edit(a_list):
        a_list.append(0)
    
    spam = [1, 2]
    edit(spam)
    print(spam)
  6. What would the following snippet of Python code print if run?

    def edit(a_list):
        a_list.append(0)
    
    spam = (1, 2)
    edit(spam)
    print(spam)
  7. What would the following snippet of Python code print if run?

    def edit(a_list):
        a_list = a_list + (0, -1)
    
    spam = (1, 2)
    edit(spam)
    print(spam)
  8. What would the following snippet of Python code print if run?

    def edit(string):
        string.capitalize()
    
    spam = "one"
    edit(spam)
    print(spam)
  9. What would the following snippet of Python code print if run?

    import turtle
    
    def edit(a_turtle):
        a_turtle.goto(1, 0)
    
    spam = turtle.Turtle()
    edit(spam)
    print(spam.position())
  10. Create a Python function that takes a list of numbers and returns a new list that is equivalent to the normalization of the input array. A list is normalized by scaling and shifting all of the elements of a list such that the smallest value is 0.0 and the largest value is 1.0. Values in the list should maintain their relative differences. For example the list [25, 50, 75] would be normalized as the list [0.0, 0.5, 1.0].

  11. Create a Python function that takes a list of numbers, normalizes the input list, and does not return anything.