Thanks to Dr. Alan McLeod for the content of this lab.

Sorting

Open the program you wrote for the "Sequential Search" exercise last week. Write a helper function showFirstAndLast(...) with three parameters: one for the weather data, one for a number m of entries to print and one for a collection of dictionary keys. This function must print the key:value pairs for the first m and last m records in the database. Add a call to this method in main() with the year as a key (and any others you might like) to display some of the unsorted data.

Write a sorting function for the weather data using the algorithm of your choice. The function must have two parameters: one for the weather data and one for a key. The function must sort the dictionaries in the list using the value stored at the given key. Add a call to this method in main() and sort by year. To demonstrate that your sort method works, add a second call to showFirstAndLast(...).

Add code to main() which sorts the weather data by meanT. Use the sorted information to easily access and print the minimum, median and maximum mean temperatures. How does this compare to the findMin(...) and findMax(...) functions you implemented last week?

Here is a sample solution using insertion sort. For extra practice with sorting, try implementing the other two algorithms as well.

Tkinter

Here is a Tkinter program. Have a look at the code, but do not run it right away. Figure out and sketch the appearance of the window as it would appear when the program is first run. Draw the buttons as boxes and write the labels onto your sketch (don't worry about colours!). How would the window appear after the "Hop!" button has been clicked once? After 3 clicks? After 6 clicks? Run the program to see how close you are to the true appearance of the window.

More Exercises

Try creating GUIs for the programs you wrote for Assignment 1. Instead of asking the user for input on the command line using the input(...) function, create an interface with Entry widgets for input. Make sure to include a Label for each Entry widget to describe what is expected. Add a Button which performs the calculation when clicked and displays it in a separate Label. Don't forget to catch any ValueErrors that may be thrown.