CPTR 124 Fundamentals of Programming
In this lab you will write a program that displays a set of numeric data in a graphical manner.
- Teams
You are encouraged to work with a partner for this lab. You and your partner should begin thinking about the problems and begin writing the code before lab time.
- What to do
Write a Python program that reads in an arbitrary number of nonnegative integer values. An integer value less than zero terminates the input. After all the values have been entered, the program prints a histogram of the number of values in the following ranges: 0-99, 100-199, 200-299, 300-399, 400-499, and 500+.
If the following values are entered:
115 556 130 605 714 808 415 494 769 278 451 114 816 398 669 481 166 81 335 459 388 504 548 402 646 299 458 733 187 615 932 983 342 302 483 543 358 373 469 881 458 114 214 253 265 869 55 198 337 889 533 694 343 307 620 712 710 650 827 62 115 951 257 116 801 31 192 820 8 686 208 444 300 671 200 325 562 761 185 197 126 380 771 384 131 397 773 570 523 262 510 304 360 793 481 391 313 534 145 645 -1the resulting histogram would be
0- 99 5|****** 100-199 15|******************* 200-299 9|*********** 300-399 19|************************ 400-499 12|*************** 500+ 40|**************************************************Each line lists the data range, the actual number of values in that range, a vertical bar, and then the bar of asterisks representing that quantity.
The longest bar always should contain 50 asterisks, and the other bars should be scaled proportionally. The sample input
450 401 3 78 444 200 -1would display
0- 99 2|********************************* 100-199 0| 200-299 1|***************** 300-399 0| 400-499 3|************************************************** 500+ 0|and input consisting merely of
-1would produce
0- 99 0| 100-199 0| 200-299 0| 300-399 0| 400-499 0| 500+ 0|Be sure your program handles ties properly:
1 1 100 100 -1would produce
0- 99 2|************************************************** 100-199 2|************************************************** 200-299 0| 300-399 0| 400-499 0| 500+ 0|The formatting of your output should be identical to example outputs above.
How do you scale the bars? Once you have tallied the quantity in each of the ranges, determine the maximum range. Assume the quantity in the maximum range is m. The length of the bar representing a range of size r would be r/m*50. Observe that m/m*50 = 50, so the longest bar is limited to 50 asterisks, and smaller ranges will be proportionally shorter.
You are welcome to write your own functions if you wish, but you are not required to do so.
- Check out
Your finished programs will be evaluated for correctness and compliance. When approved, you should submit your Python source file to http://eclass.e.southern.edu.