As usual, create two directories for today's class. Create a
directory called lecture13
under activities, and
a directory called lab13
under labs.
I have, purposefully, been hiding some information about how for
loops work. It seems that it might have been a mistake to do so.
Specifically, how range
operates. Hopefully, seeing
how range operates will alleviate some of the confusion.
I brought up the Fibonacci Sequence in the bonus question on the test. One of the neat things about the sequence is its exceedingly simple definition. Let Fn define the nth number in the Fibonacci sequence, where F1 = 1 and F2 = 1. Then, the nth number can be computed as: Fn = Fn - 1 + Fn - 2
Create a file called fib_spiral.py
in
your lecture13 directory. Create a
function fib
, which takes a single
parameter n. This function should return
the nth Fibonacci number. This
function should work for all n > 0.
turtle
way
The only way you know how to write interactive programs thus far is by
using the input
function. As many of you have seen, this
is quite cumbersome when your program is using turtle to display
things. Wouldn't it be nicer if the user could interact with the mouse?
Yes, we are doing fish again. You can copy your fish code from lecture 11 by executing the following commands:
cd ~/cs120/labs/lab13 cp ../lab11/fish.py .
If your previous draw_fish
method did not work entirely
correctly, spend some time to fix it. You can use the helpful image
below as your guide: