Quiz 1 Information

Quiz details

Quiz Logistics

Material covered

The quiz will focus on the material that we have discussed in class during Week 1, modules 1 and 2.

You must be familiar with concepts that were introduced in the pre-class videos, in-class discussion, or on the problem sets that were not covered in the videos or readings.

Preparing for the quiz

Additional practice problems

  1. Given the string s = 'Marathon', evaluate the following expressions:

    1. s[0]
    2. s[0:1]
    3. s[1:]
    4. s[-1]
    5. s[3: :-1]
    6. s[2: :2]
  2. Given the list myList = [3, 2, -1, [4, 7], 5], evaluate the following expressions:

    1. myList[0]
    2. myList[0:1]
    3. myList[-1]
    4. myList[3]
    5. myList[:2]
    6. myList[2: :2]
  3. What is printed by the following working Python program?

    def dog(x):
        print('in dog, x is', x)
        y = cat(x - 1) + cat(x + 2)
        print('in dog, y is', y)
        return y
    
    def cat(y):
        print('in cat, y is', y)
        x = rat(y * 2) + 3
        print('in cat, x is', x)
        return x
    
    def rat(x):
        print('in rat, x is', x)
        return 2 * x
    
    y = dog(3)
    print('at this level, y is', y)
    
  4. What is printed by the following working Python program?

    def mystery(x):
        print('x is', x)
        if x < 1:
            return 2
        else:
            p = 6 - mystery(x - 1)
            print('p is', p)
            return p
    
    y = mystery(3)
    print('y is', y)
    
  5. Write a function to_celsius(degrees_f) which returns the temperature in Celsius, given the temperature in degrees Fahrenheit. The temperature in Celsius is the amount in Farenheit - 32, times 5/9. For example, 50 degrees F is 10 degrees C.