# # # Tracing Problems # # # Note: To check your answers place the code in a Python program and execute. # # #1. What will be the printed value of total_1 after executing the following? total_1 = 10 + 23 / 10 * 3 + 5 - 10 print total_1 #2. What will be the printed value of total_2 after executing the following? total_2 = 10 + 23 / 10.0 * 3 + 5 - 10 print total_2 #3. What will be the printed value of total_3 after executing the following? a = 3 b = 5 c = 1.5 d = 2 total_3 = (a + b) * (c * (b % d - a)) print total_3 #4. What is printed by the following loop? for x in range (3,15): print "|" , x , #5. How many "x" characters will be displayed if f1(1,20) is executed? def f1(begin, end): for x in range (begin, end + 1): if x > 5: print "x" , print #6. What will be printed by the following loop if list = [1,3,5,7,9,11,13,15]? def f2(list): for x in (list): print "|" , x * 2 , print "|" #7. What is printed when function f3 is executed? def f3(): x = 1 y = 5 sum1 = 0 sum2 = 0 for z in range (x, y+1): sum1 = z + 2 sum2 = sum2 + sum1 print " sum1 = " , sum1 , " sum2 = " , sum2 #8. What is printed by f4(m) if m = [[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]] def f4(matrix): print "------------------------------" for row in range(0,len(matrix)): for col in range(0,len(matrix[row])): print matrix[row][col] , print print "------------------------------" #9. What is printed by f5(m,2) if m = [[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]] def f5(matrix, factor): f4(matrix) for row in range(0,len(matrix)): for col in range(0,len(matrix[row])): matrix[row][col] = matrix[row][col] * factor f4(matrix) #10. Using following function, execute the code that follows. def f6(a, b): a = a + 2 * b b = a * b print "a = " , a , " b = " , b # now execute the following # >>> x = 2 # >>> y = 4 # >>> f6(x, y) # >>> print "x = ", x , " y = " , y