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, i.e., modules 1 and 2. You must be familiar with concepts and syntax that were introduced in the pre-class videos, in-class discussion, or on the problem sets even if they were not covered in the videos or readings, specifically including:

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. 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, the function call to_celsius(50) would return the value 10, because 50 degrees F is 10 degrees C.

  4. Write a function make_password(word, num, symbol) which takes 3 parameters: a word, a number, and a symbol, and returns a string which is the password. The password must contain the first 4 characters of word, the number num, the symbol, and then the rest of the word.

    For example the function call make_password('beatles', 1962, '!') would return the string 'beat1962!es'.

  5. Write a function is_factor(x, n) and returns the boolean True if x is a factor of n (i.e., a divisor without remainder), and False otherwise.

    For example, the function call is_factor(3, 12) would return True, and the function call is_factor(3, 11) would return False.

  6. Write the function calc_pay(rate, hours) that returns the amount of pay earned, calculated as follows: the first 40 hours paid at regular rate; hours above 40 paid at 1.5 times the rate.

    Examples:

    calc_pay(25, 20) # 25 hours, $20/hour (all regular pay) 500

    calc_pay(45, 20) # 45 hours, $20/hour (5 hours are overtime) 950.0