Difference between revisions of "CSC111 Homework 9 2011"
(→Problem #1) |
(→Problem #1) |
||
Line 17: | Line 17: | ||
:Note that this file does not have triple double-quotes around the list of presidents, and that it does have a header, i.e. the first line defines what the different fields are, but is not a valid president line. | :Note that this file does not have triple double-quotes around the list of presidents, and that it does have a header, i.e. the first line defines what the different fields are, but is not a valid president line. | ||
+ | ==Requirements== | ||
+ | * Your program should use functions. Study Homework 7 a second time to get inspiration for your program organization. | ||
* The output of your program should be only a few lines long. We do not want to see the list of presidents. Just something like this: | * The output of your program should be only a few lines long. We do not want to see the list of presidents. Just something like this: | ||
Line 27: | Line 29: | ||
* The number of presidents (44) should be the number found by your program in the text file. When I test your program, I may provide a '''presidents.txt''' file with fewer than 44 presidents. Or a file that has just a header and no presidents at all! Or even a file with nothing in it, just empty. Be sure you test your program well so that it doesn't crash on any of these potential input files. | * The number of presidents (44) should be the number found by your program in the text file. When I test your program, I may provide a '''presidents.txt''' file with fewer than 44 presidents. Or a file that has just a header and no presidents at all! Or even a file with nothing in it, just empty. Be sure you test your program well so that it doesn't crash on any of these potential input files. | ||
+ | ==Submission== | ||
* Submit your program as follows: | * Submit your program as follows: | ||
rsubmit hw9 hw9a.py | rsubmit hw9 hw9a.py | ||
− | |||
:if you worked on beowulf, or submit your program using this page: http://cs.smith.edu/~111a/submit9.htm | :if you worked on beowulf, or submit your program using this page: http://cs.smith.edu/~111a/submit9.htm |
Revision as of 12:52, 13 November 2011
--D. Thiebaut 12:28, 13 November 2011 (EST)
Problem #1
- Write a program called hw9a.py that outputs the average length of the presidency of US presidents, categorized by party. Your program should get the information from a file called presidents.txt, whose contents is available here.
- If you are working on beowulf, you can get a copy of the file into your account this way:
getcopy presidents.txt
- Note that this file does not have triple double-quotes around the list of presidents, and that it does have a header, i.e. the first line defines what the different fields are, but is not a valid president line.
Requirements
- Your program should use functions. Study Homework 7 a second time to get inspiration for your program organization.
- The output of your program should be only a few lines long. We do not want to see the list of presidents. Just something like this:
Average length of presidency. File presidents.txt contains 44 presidents. Democratic presidents: x.xx years Republican presidents: x.xx years Others: x.xx years
- The number of presidents (44) should be the number found by your program in the text file. When I test your program, I may provide a presidents.txt file with fewer than 44 presidents. Or a file that has just a header and no presidents at all! Or even a file with nothing in it, just empty. Be sure you test your program well so that it doesn't crash on any of these potential input files.
Submission
- Submit your program as follows:
rsubmit hw9 hw9a.py
- if you worked on beowulf, or submit your program using this page: http://cs.smith.edu/~111a/submit9.htm