Comp 115 Test 3 Study Guide

Test on March 31 EST

I tried my best to list the topics for the exam but I may have forgotten one or two. Your default assumption should be that if I covered it in class before files, it is fair game for the exam.

I will add practice problems as I find new interesting questions, so come back to this page every few days, more practice problems may have appeared.

If you want to see the short video I recorded about the test, click here.

In addition to all concepts from Test 2,

Functions

Decisions

Lists

Practice Problems

  1. Finish any lab exercises that you did not have time to complete during lab time. Remember, I added a whole page of exercise for the week of Fall break during which we did not have lab.
  2. Suppose that the assignment myList = ["fish", 3, 5.0, 1729, [7,8,9], 10, 39, 67] was just executed. What value would Python give to each of the following expressions:
    • myList[0]
    • myList[4]
    • myList[2:6]
    • myList[0:1]
    • myList[1:7:2]
    • myList[0][3]
    • myList[4][::2]
    • myList[:3:-3]
    Find a slice of the list in myList that would evaluate to the following value:
    • [3, 5.0, 1729]
    • [8,9]
    • [39]
    • "ish"
    • [10, [7,8,9], 1729]
  3. Write a program that asks the user for an input string and prints the string on screen without modifications if the string contains an even number of characters, and prints the reverse of the string if it contains an odd number of characters.

  4. The following is a (silly) large if statement:
      a = int(input("Enter a first number "))
      b = int(input("Enter a second number "))
      c = int(input("Enter a third number: "))
      if a > b:
          if b > c:
              print("Spam")
          else:
              print("Parrot")
      elif b > c:
          print("Cheese Store")
          if a >= c:
              print("Cheddar")
          elif a < b:
              print("Gouda")
          elif c == b:
              print("Swiss")
      else:
          print("Trees")
          if a == b:
              print("Chestnut")
          else:
              print("Birch")
      print("Done")
    Show what would be printed on screen for each of the following inputs:
    • 3, 4, 5 (meaning the user enters 3, then 4, then 5)
    • 3, 3, 3
    • 5, 4, 3
    • 3, 5, 2
    • 5, 4, 7
    • 3, 3, 2
    You can copy-paste all this code in Wing101 if you wish to test your answer.
  5. Other practice problems TBA