CSC 111: Introduction to Computer Science

HW 3: Data Types, Math, Date and Random Libraries

Due Wednesday Feb 16 Midnight, via Moodle

SUBMIT as HW3_Fib.py and HW3_Snow.py

Office Hours Monday 2-3; Tuesday 1:30-2:30


Feedback on homework programs and samples

Part 1: Fibonacci

Write a program to find and print out the Fibonacci sequence of n numbers. See problem 16 on page 74 of the text, or simply Google Fibonacci. Also graph the results in a manner you find interesting and visually clear and pleasing.

Presenting information in a manner that communicates your message effectively to others is a very high level skill. You only need to use the elements of the graphics library that we have already seen, but do work to make your graph as clear and complete as possible, given what you have learned so far. Next week in class we will see more operations that will let you label things with text.

As with part of HW 1 from the beginning of the semester, for this part of HW 3, completing the task above, using the same coordinates for the graph, regardless of what value of n is input, will earn a score of B+/A-. To receive a score of 'A,' you will also need to dynamically set the graph coordinates so that they are scaled differently depending upon what value of n is input. For example, if the maximum value in the Fibonacci sequence is 8, then the y-axis could be scaled to 8, or perhaps 10. If the maximum Fibonacci number is 55, then the y-axis should be scaled to perhaps 60. The x-axis will also need to be scaled appropriately. We do not have the tools, yet, to do this part of the HW elegantly. You only need to show some thought for this, that will work well for the first part of the Fibonacci sequence, and will still work ok as the sequence grows. You will also need to use the "trial and error" method discussed in the text, and this part of the HW should help you become more comforable with trial and error in programming.

The objective of this exercise is for you to

  1. Get some practice using the math library and/or built in math operators.
  2. Write a program that uses the accumulator for loop
  3. Gain more experience with the graphics library
  4. Gain some comfort with trial and error in programming
Note that there is a difference between (i) using the web as a resource to help think through algorithms, and (ii) plagiarism. You can plagiarize computer code just as you can plagiarize prose. Do feel free to use the web as a resource, but just as with the written word, you need to present your own work, and if you do use an outside source, cite that source by including the URL in your comments. Finally, you can complete this assignment using only what we have learned in class - do not use constructs that you find on the web, and do not fully understand.

SUBMIT as HW3_Fib.py

Part 2: Random Snow Fall and Punxsutawney Phil

Investigate the 'random' library. Using this library, generate numbers that you will use as a prediction of the number of inches of snow that will melt each day over the next four weeks. Alse generate random numbers for the number of inches of snow that will fall and accumulate each day over the next four weeks. Will your program show us that spring will be coming early, or are we going to get buried under never-ending mountains of snow?

Graph the results in a way that communicates three values - the snow melt, the snow fall and the net amount of remaining snow, each day.

You need to determine:

There are two main functions available to generate random numbers. One generates floating point numbers, and the other generates integers.

SUBMIT as HW3_Snow.py