CSE 1310 -004 Fall 2011 Tiernan Sample questions for Test 2 prep 1) Write a Python function to take a dictionary like pratchett below as an input parameter and do the following. Take every word in the dictionary and put the words into a single list that is sorted by the length of the words with the shortest words first. If two words are the same length they can go in any order. Return the list as the result of the function. pratchett = {a:['angua','arthur'], c:['carrot','colon'], g:['gaspode'],s:['sam','sybil'],v:['vetinari','vimes']} 2) Give at least three examples of real-world situations where a Python list would be a reasonable way to store the data if you were writing a program to manage that situation. If the data should be sorted, state how the data should be sorted. 3) Write a Python program that asks a user to enter the birthdates and ages of their family members and then write that data to a file so that each line of the file has the form: day_int, month_int, year_int, age_int, name_string where the four numbers are stored as integers and the name is stored as a string. Allow the user to enter as many dates as desired. 4) Imagine a Python function that does the following. The function should take in a number as input and error check that it is a number. If it is not a number, print an error message and return the value -99. If it is a number do one of the following things. If it is an even integer, return the value 2. If it is a negative number and not an even integer, return the value -1. If it is evenly divisible by 3 and not negative or an even integer, return 3. If it is a floating point value with a decimal portion, i.e. not equal to an integer value, and not any of the previous things, return 1. Otherwise, return 0. 4a) How many different values can be returned by the function in question 4? 4b) What value would represent an error in input? 4c) What would the value 0 returned from the function tell you? 4d) Are there any input numbers that would not return a value? Why or why not? 4e) What control statements would you use to write the function above and why? 4f) Think of an application where you might need to do similar sorts of testing on input values and describe the application and at least three of the tests you would do to the input values.