Last updated: 2025-02-28
This assignment is due March 15th at 11:59 PM. Submit your solution on BrightSpace, under the “Unit 6” assignment.
Please copy your code into the text box, making sure to indent it properly with whitespace so that it appears the same as in IDLE or wherever you wrote the code. This will make it easier for me to grade.
You can submit multiple times. I will only grade your last submission.
This assignment uses the CPI data we saw in class, from this link: https://futureboy.us/frinkdata/cpiai.txt
You should download the data using the urllib
method we saw in class, not manually.
In this task, we are going to write a program test6.py that reports Consumer Price Index and its average value for any year selected by the user.
Additionally, the user will be able to choose the months of the year they want to display. The program will have to use list comprehension for transforming the list of months into the list of corresponding CPI values.
Below are some sample queries, which is how your program should appear when the final version is run. The results are given in monospace
, the user input is given in bold, and some comments (not input by the user) are given in italics.
Enter query: 1950
[23.5, 23.5, 23.6, 23.6, 23.7, 23.8, 24.1, 24.3, 24.4, 24.6, 24.7, 25.0] 24.066666666666666
Enter query: 1950 5 6 (May and June of 1950)
[23.7, 23.8] 23.75
Enter query: 1950 1 3 5 7 (January, March, May, and July of 1950)
[23.5, 23.6, 23.7, 24.1] 23.725
Enter query:
Enter query: 1950
[23.5, 23.5, 23.6, 23.6, 23.7, 23.8, 24.1, 24.3, 24.4, 24.6, 24.7, 25.0] 24.066666666666666
Enter query: 2000
[168.8, 169.8, 171.2, 171.3, 171.5, 172.4, 172.8, 172.8, 173.7, 174.0, 174.1, 174.0] 172.19999999999996
Enter query:
1950 1 3 5 7
requests the data for January, March, May, and July of 1950. If the months are not specified, report full year. The average should be computed only for the reported months.Enter query: 1950
[23.5, 23.5, 23.6, 23.6, 23.7, 23.8, 24.1, 24.3, 24.4, 24.6, 24.7, 25.0] 24.066666666666666
Enter query: 1950 1 3 5 7
[23.5, 23.6, 23.7, 24.1] 23.725
Enter query: 1950 5 6
[23.7, 23.8] 23.75
Enter query:
You should be able to do all of the tasks with only the Python topics we covered in class so far.
If you want to use more complex functionality than what we discussed in class, the Python documentation may be helpful: Python 3.10 documentation