CS 111 - 9/27/16 Exam 1 in class on Thursday 9/29/16 20 multiple choice questions (3 pts each) 2 write code questions ( 20 pts each) x = 1 z = 0 for w in range(5): z = z + x x = x + 1 --------- Answer x: 1 2 3 4 5 6 z: 0 1 3 6 10 15 ============= # the above code is the sanme as the follow x = 1 z = 0 z = z + x x = x + 1 z = z + x x = x + 1 z = z + x x = x + 1 z = z + x x = x + 1 z = z + x x = x + 1 ==================== z = 0 for w in range(5): z = z + w w: 0 1 2 3 4 z: 0 0 1 3 6 10 ================== z = 0 x = 0 for w in range(5): x = 8 - w z = z + x w: 0 1 2 3 4 x: 0 8 7 6 5 4 z: 0 8 15 21 26 30 ============================= z = 0 x = 1 for w in range (6): x = w % 3 z = z + x w: 0 1 2 3 4 5 x: 1 0 1 2 0 1 2 z: 0 0 1 3 3 4 6 From Long Division: 10 / 3 ==> 3 R 1 For the Modulus OP: 10 % 3 ==> 1 ==================================== 5 + 4 * 2 10 - 3 - 2 ====================== x = 0 z = 1 for i in range (5): x = x + z z = z + i i: 0 1 2 3 4 x: 0 1 2 4 8 15 z: 1 1 2 4 7 11 Modulus gives the remainder from a long integer division