Due Thursday, November 1, at the start of class.
Write a Python script that gathers input data and calculates statistics.
Use the Python that you have learned to write a simple data analysis tool.
The script will ask the user for some data observations, each of which consists of one text label and its associated numeric value. For example, I entered U.S. states (labels) and their 2010 populations (values). After some input, the script might have the following data (populations are in thousands):
Label | Value |
---|---|
Wisconsin | 5687 |
Illinois | 12831 |
Michigan | 9884 |
Iowa | 3046 |
The script should cycle through the following steps:
A typical interaction might look like the following. The exact formatting is not required. In this sample interaction, the yellow highlighting shows what the user typed.
OBSERVATIONS <none> Label? Wisconsin Value? 5687 ---------------------------------------- OBSERVATIONS Wisconsin: 5687.00 STATISTICS Count: 1 Sum: 5687.0 Mean: 5687.0 Label? Illinois Value? 12831 ---------------------------------------- OBSERVATIONS Illinois: 12831.00 Wisconsin: 5687.00 STATISTICS Count: 2 Sum: 18518.0 Mean: 9259.0 Label?
How the user will quit the script? Maybe if the label input is the empty string? Maybe a special label or value that tells the script to quit? Pick something and implement it.
The program should not attempt to save its state. That is, when you quit the program and run it again later, it will start with no observations.
Tip: If the user enters the same item a second time, it should replace the original item; that is, you do not need to check to see if an item already exists, just store the data.
Tip: If the user tries to enter the same item more than once, but spells it differently, it will end up being a separate item. That is, your script does not need to be clever or fancy about item names — just accept what the user types.
Testing your code is very important! If you do not run your code, you will make mistakes and probably not receive full credit. And even just running your code once may not be enough. Try different cases and make sure things work as you expect.
Here are some specific tests to consider:
If the requirements above were easy, try one or more of the following challenges. No extra credit, just extra learning!
RANGE FREQUENCY ------- ---------+---------+---------+ 0M- 5M XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5M-10M XXXXXXXXXXXXXXX 10M-15M XXX 15M-20M XX 20M-25M 25M-30M X 30M-35M 35M-40M X
Start your script the right way! Here is a suggestion:
#!/usr/bin/env python """Homework for CS 368-4 (2012 Fall) Assigned on Day 03, 2012-10-29 Written by <Your Name> """
Do the work yourself, consulting reasonable reference materials as needed. Any resource that provides a complete solution or offers significant material assistance toward a solution not OK to use. Asking the instructor for help is OK, asking other students for help is not. All standard UW policies concerning student conduct (esp. UWS 14) and information technology apply to this course and assignment.
All homework assignments must be turned in by email! Attach your Python script to the email as a
text .py
file. See the email page for more details about formatting, etc.