< Back

Activity 10: Test Review

  1. Explain why functions are useful.

  2. For each of the following snippets of Python code, give what would be printed to the command line if run. If the snippet will not print anything because of an error, just put error.

    1. print(7 // 2)
    2. print(7 / 2)
    3. def spam(eggs):
          return eggs * eggs
      ham = spam(spam(2))
      print(ham)
    4. def spam(eggs, ham):
          eggs = ham
          return ham
      eggs = 2
      ham = eggs + 1
      spam(eggs, ham)
      print(eggs)
    5. spam = 1
      for i in range(5):
          spam = spam / i
      print(spam)
    6. for i in range(-10, 10, 3):
          print(i, end=' ')
  3. Write the function average(num1, num2, num3) that returns the average of the three specified numbers.

  4. Write the function sum_of_threes(num) that returns the sum of all positive integers that are evenly divisible by three and less than the specified integer.