PRACTICE QUIZ 2, Swarthmore College Fall 2008 Q1] For each of the following four expressions, show the value that will be returned by the Python interpreter. Assume that you already have text = "swarthmore college" and you have imported the string library using from string import *. split(text) upper(text) text[1:5] "4" + text[11:20] + "5" Q2] What is the output of the following program? def main(): word = "boz" result = "" for letter in word: result = result + chr(ord(letter) - 1) print result Q3] Consider the program below which is intended to determine whether a given number is negative, zero, or positive. def testNumber(): n=input("Enter a number: ") if n < 0: print "negative" if n > 0: print "positive" else: print "zero" What will be printed if the user enters 5 at the prompt? What will be printed if the user enters -5 at the prompt? What will be printed if the user enters 0 at the prompt? Does the program give the desired result? If not, write a corrected version below. Q4] A person is eligible to be a US senator if he or she is at least 30 years old and has been a citizen for at least 9 years. Write a program that takes a person's age and years of citizenship as input and returns their eligibility for the Senate. For example: >>> main() Enter your age >> 30 Enter years US citizen >> 5 Eligibility for the Senate: You have not been a US citizen long enough. >>> main() Enter your age >> 30 Enter years US citizen >> 10 Eligibility for the Senate: You are eligible! >>> main() Enter your age >> 29 Enter years US citizen >> 10 Eligibility for the Senate: You are too young. Q5] Finish the code for the program below so that it produces the following pattern of stars of some size, n, entered by the user (in this example, n is 4): * * * * * * * * * * def main() : print "This program prints out a pattern of stars" n = input("Enter a value for the size of the pattern: ")