CS21 PRACTICE QUIZ 3, Swarthmore College Spring 2008 Q1] Write a function called max that takes two numbers as parameters and returns the largest of the two numbers. In the case that both number are equal, your program should return either of the parameters. In addition to the max function, write a main function that calls your max function. Q2] Consider the program shown below: def helper1(word, letter): for i in range(len(word)): if word[i] == letter: return i return -1 def helper2(word, letter): total = 0 for ch in word: if ch == letter: total = total + 1 return total def main(): test = "frisbee" check = "e" print helper1(test, check) print helper2(test, check) main() 2a] Define the term argument and give an example from the program above. 2b] Define the term parameter and give an example from the program above. 2c] Describe the steps that occur when a function call is executed. Use an example from the above program. 2d] What would be better names for helper1 and helper2? 2e] What is printed when this program is run? Q3] Using the graphics library, write a complete program that will draw a picture of a circle and two lines as described below. The window should have a vertical line from top to bottom that is centered left to right. A second line should be horizontal from the left of the window to the right of the window centered top to bottom. The result is a cross of two lines that cross in the middle of the window. Finally draw a circle in the top left corner of the window that touches both lines as well as the top and left sides of the window. Use a window that is 200 by 200 pixels. Your program should wait for a mouse click before closing the graphics window. Q4] Many US companies pay time-and-a-half for any hours worked above 40 in a given week. For example, an employee who makes $10 an hour and worked 45 hours in a particular week would make $10*40 + $15*5 = $475. Below is a program that takes the number of hours worked and the hourly rate as input and calculates the week's wages. def main(): hours = input("Enter the number of hours worked this week >> ") rate = input("Enter the hourly rate >> ") if hours <= 40: wages = hours * rate else: wages = 40 * rate + (hours - 40) * 1.5 * rate print "Wages are", wages 4a] Rewrite this program so that it now uses a function called wages that takes the hours worked and hourly rate as parameters and returns the week's pay. Be sure to show the updated version of main. 4b] Even though this second version is longer than the first version, give three reasons why it is better to use a function in this situation.