Due: Thursday, October 8th
In this lab you'll practice describing numerical sequences and patterns and to create a number of programs to accomplish various tasks using loops. As usual, READ THE LAB CAREFULLY!
Problems 1 through 4 contain the initial entries in a few sequences of numbers. For each of these problems, specify the following three things:
For example, if the given sequence was 1, 3, 5, 7, 9, 11,... then you answers should be:
Write your solutions in a text file called sequences.rtf.
1. 5, 6, 7, 8, 9, 10,...
2. 0, 3, 6, 9, 12, 15,...
3. 0, 1, 4, 9, 16, 25,...
4. 0, 1, 3, 7, 15, 31,...
The Fibonacci numbers are one of the most famous sequences of numbers, and are defined as follows. The first two Fibonacci numbers are defined to be F(0) = 0 and F(1) = 1. Each later Fibonacci number is defined to be the sum of the previous two. More formally, we'd say that F(i) = F(i-1) + F(i-2) for all i > 1. So the first few Fibonacci numbers are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc.
5. Specify the next three Fibonacci numbers.
6. Let S(x) be the sum of the first x Fibonacci numbers. So S(0) = 0 (F(0) = 0). And S(1) = 1 (F(0) + F(1) = 1). And S(2) = 2 (F(0) + F(1) + F(2) = 2). Compute the values of S(x) for all values of x from 0 through 8.
7. Conjecture a general formula for the value of S(x) in terms of the Fibonacci numbers (without the summation).
Below are a few patterns. Give the following line in the pattern, and write a description (in English) of what line n of each pattern would look like, for a general n.
For example, if the pattern was
1
12
123
1234
12345
Then a valid answer would be: 123456 is the next line, and in general, line n consists of all integers from 1 to n in increasing order.
8.
111
222
333
444
555
9.
1
22
333
4444
55555
10.
1
2211
333222111
4444333322221111
5555544444333332222211111
Many of you may know the childrens' (and sailors'?) song 99 bottles of beer on the wall. If not, no worries, I'll fill you in. The first line of the song goes something like this:
99 bottles of beer on the wall, 99 bottles of beer... if one of those bottles should happen to fall, 98 bottles of beer on the wall!
The next line is just like the first, except the numbers have gone down by 1 each; instead of 99... 99... and 98 bottles of beer, we have 98... 98... and 97 bottles of beer. In the next line it goes 97... 97... 96. When you get to 0 bottles of beer... actually come to think of it, I have no idea how the song ends, but I sort of doubt anyone has ever gotten that far, so let's not worry about it. Your task is to write a program that prints out the first 15 lines of this absurdly ridiculous song. Call your program Beer.py. Don't use loops. Copy-paste is your friend.
Now use loops to accomplish the same task, but go until there are 0 bottles of beer on the wall. Call the resulting program LiteBeer.py .
For this Part, there are a bunch of mini programs you'll need to write. DO NOT SUBMIT THESE! They are merely meant to help you figure out the more complicated problems in Part 5. That said, it will be much harder to complete Part 5 if you do not complete Part 4. You should save these to your own personal student directory. Test them to make sure they work.
Write programs to solve the following seven problems. These programs are to be submitted to your assignment drop box. Be sure to use the specified program name and carefully check that each program actually does what it should.
There are a number of methods (functions) associated with the GraphWin class that are used to interact with individual pixels (rather than drawing larger shapes). In particular, the method
plotPixel(x, y, Color)
sets the color of the pixel at coordinates (x,y) to have the color given by the string Color. Recall that you can create an appropriate color string by invoking the function:
color_rgb(red, green, blue)
where the parameters red, green, and blue are integers with values from 0 to 255 that specify the intensity of each of the color components.
Create a program called [Shaded.py] that creates an image which is 256 x 256 pixels large. Loop over all pixels in the image (nested loops will probably be needed here) and set their color according to the following scheme: set the red value of any given pixel to be the value of its x coordinate; set the blue value to be the value of its y coordinate; and set the green value to be 0. Then display the image. Remember, in an image that is x pixels wide, the index of the last column is x-1 (and similarly for the vertical indexing).
Upload all your programs to the folder Lab05. This folder should contain: