Comp 115 Test 2 Study Guide

Test on October 8-9 (depending on your lab section) 3:30-4:00 in lab

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 the end of "if" statements, 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.

In addition to all concepts from Test 1,

Strings

Objects and Graphics

Decisions

Practice Problems

  1. If you did not finish the lab exercises, try to finish them. Some of these questions tend to be a bit harder than what I could ask on the test, but they are good practice nonetheless.

  2. Suppose that the assignment myString = "a completely random string" was just executed. What value would Python give to each of the following expressions:
    • myString[20:-1]
    • myString[20::-1]
    • myString[:5]
    • myString[1:15:3]
    Find a slice of the string contained in myString that would evaluate to the following values:
    • "pletely"
    • "eyn i"
    • "tdy"

  3. Write a program that asks the user for an input string and prints the string on screen as is if the string contains an even number of charcters, 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.