# THESE PROBLEMS ARE JUST FOR PRACTICE AND TO GET AN IDEA OF KINDS # OF QUESTIONS THAT MIGHT BE ON TEST 1. # THE ACTUAL QUESTIONS MAY BE SIGNICANTLY DIFFERENT. ################# ## Reading Code # ################# # What does Python evaluate each of the # following lines to be # (and what are the types of each expression): 9 % 4 12 % 4 9 // 4 9 / 4 "34" + "10" # Suppose S is the string "BCC Math". # How does Python evaluate the following # expressions S = "BCC Math" S[2] S[2:6] S[2:] S[:2] S[:-2] S[3:-2] 4 < 3 2 == "2" S[2] == "C" # What does the following code print? # Make a flowchart of the program. k = -5 if k > 0: print(k) elif k < -5: print(k*2) elif k == -4.9: print(k+2) else: print(k - 1) print(k+10) # What is the value of k after running the # following program? # Show your work by doing a trace. k = 2 k = -5 if k > 0: k = k + 2 elif k < -5: k = k*2 elif k == 2: k = k - 1 else: k = k**2 # What does the following code print L = [9, 8, 4, 100] if L[2] > 7: L[2] = 7 else: L[2] = 0 print(L) ################ # Writing Code # ################ # 1 # Write a program that swaps the values in # variables A and B. # 2 # Write a program that takes in 5 numbers # as user input and prints their average. # 3 # Write a program that prompts the user # for two numerical inputs (L and W) # and prints out the area and perimter of a rectangle # with length L and width W. # 4 # Do the last program again, but do it so # that it complains if either the length # or width is not a valid number and quits. # 5 # One pound is 0.45kg. # 1) Write a program that takes gets a number # as user input and prints out its conversion # to kg. # 2) Write a program that takes a number # as user input and outputs its conversion # to pounds # 6 # Write a program that takes 3 numbers as # user input and prints out the minimum of the 3 # numbers # 7 # Write a program that takes 3 positive # numbers as user input and prints out the middle # number if the 3 numbers are distinct, # and outputs -1 if they are not distinct # 8 # Write a program that takes a positive # integer n as user input, and prints out the number # of positive even integers less than n.