CS21: Quiz 2 Study Sheet

In addition to all concepts from Quiz 1,

You should be able to define the following terms:

You should understand and be able to use the following Python concepts:

Practice problems:

  1. Show the value and type of each of the following, given these assignments for x, y, L, and S:
    x = 5
    y = 13
    L = ["pony", "zebra", "donkey", "unicorn"]
    S = "we love computer science"
                             
                               VALUE:               TYPE:
                               -----                ----
    x < 10 and y < 10
    
    x < 10 or y < 10
    
    x < 10 and x > 0
    
    x > 10 or x < 0
    
    range(1,100,10)
    
    (5/y) > 7.0
    
    "LOVE" in S
    
    len(S) >= 10
    
    range(len(L))
    
    S[8:12] + S[17:20]
    
    len(L[2])
    
    
  2. Trace the following program and show it's output:
      x = 3
      print 0,x
      for i in range(1,6):
          if x % 2 == 0:
              x = x / 2
          else:
              x = (3*x+1)/2
          print i,x
      
  3. Write a program that accepts 5 grades (0-100) from the user and displays the average of all 5 grades, as well as the corresponding letter grade for each input (where A is >= 90, B is 80-89, etc):
    grade: 96
     that's an A
    grade: 86
     that's a B
    grade: 76
     that's a C
    grade: 66
     that's a D
    grade: 56
     that's an F
    
    the average of those is: 76.0
      
  4. Write a program that asks the user to enter some text and then displays that text with all e's and E's replaced with 3's and all s's and S's replaced by 5's. For example, if the user enters the phrase "WE love COMPUTER science", your program would display this: W3 lov3 COMPUT3R 5ci3nc3