Quiz 2 Information

Quiz details

Material covered

The quiz will focus on the material that we have covered in module 1 and problem set 1. 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. 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.

  2. Write a function same_first_two(a, b) that takes two strings, and returns True if the two strings a and b share the same first two characters, and False otherwise. Examples: >>> same_first_two(‘hermans’, ‘hermits’) True >>> same_first_two(‘led’, ‘zeppelin’) False

  3. Write a function letter_grade(score1, score2, score3) that takes three integer quiz scores, computes their average, and returns a letter grade as a string: “A” for 90 and above, “B” for 80–89, “C” for 70–79, “D” for 60–69, and “F” below 60.

    Examples: letter_grade(95, 88, 91)
    “A” letter_grade(72, 68, 74) “C” letter_grade(55, 60, 50) “F”

  4. Write a function shipping_cost(weight, destination) where weight is a floating-point number (in pounds) and destination is either “domestic” or “international”. The base rate is weight * 2.50 for domestic shipments and weight * 5.00 for international ones. If the weight exceeds 10.0 pounds, add a $15.00 surcharge regardless of destination. Return the total cost as a float.

    Examples: shipping_cost(5.0, “domestic”)
    12.5 shipping_cost(5.0, “international”) 25.0 shipping_cost(12.0, “domestic”)
    45.0 # (122.5 + 15) shipping_cost(12.0, “international”) 75.0 # (125.0 + 15)