Sale!

 CSCI 2202 Assignment 1 Solved

Original price was: $40.00.Current price is: $35.00. $29.75

Category:

Description

5/5 - (1 vote)

(1) In Lab 2, you made a program, using the turtle module, that could draw polygons
of a user-specified number of sides. Create a new program that draws the polygon,
rotated a specified number of times (you may use your program from lab 2 in this
exercise).
Enter num sides : 8 Enter num sides of polygon: 20
Enter num polygons: 10 Enter num polygons: 20
Note the alternation of colours in the drawing (you may choose any colours, just that
the alternation of colours should be kept). Make sure your figure stays within the
window for any number of sides and and number of polygons.
(2) Create a program trianglePursuit.py. For this, set up three turtles at the corners
of an equilateral triangle, of side 400 units. In this program, turtle 1 chases turtle 2 .
Turtle 2 chases turtle 3 and turtle 3 chases turtle 1. Each turtle should trace its path
(use a different color for each turtle’s path) as above. Stop the program when the
turtles meet. You may need to specify a distance (rather than an exact location) to
stop the turtles, as having multiple turtles stop in the exact location using floating
point numbers is rare.
1
2
(3) In the book Liber Abaci, Leonardo of Pisa (better known as Fibonacci) considers
pairs of breeding rabbits in an enclosure.
• At the start of month zero there is a single infant pair of rabbits.
• A pair of rabbits matures in 2 months.
• Rabbits do not breed in their first month of life.
• Each mature pair of rabbits produces an infant pair of rabbits on the last day
of each month, starting with the second month.
• Rabbits are not mortal.
Leonardo asks: How many pairs will there be one year after this pair begins breeding. For more information about Fibonacci’s problem see:
https://tinyurl.com/y5sadcpb
Let F[j] denote the number of pairs in month j. A slight modification of the above
problem gives:
F[0] = 0, F[1] = 1, and F[j] = F[j − 1] + F[j − 2], n ≥ 2
(a) Write program FibonacciSeq.py that prompts the user for a positive integer
n and then computes and prints out the Fibonacci sequence up to F[n]. You
program should print the sequence with 5 Fibonacci numbers per line (except in
the last line). The Fibonacci numbers for the range above are at most 4 digits.
Use print(’{:5d}’.format(F[j]), end=””) to print values with widths of 5
digits. This will give a reasonable display (we will examine formatted output in
the next lab). What is the answer to Leonardo’s question?
3
You will need to refer to:
https://docs.python.org/3/tutorial/datastructures.html for list methods.
(b) Make your program print compute the ratio: F[j + 1]
F[j]
for 2 ≤ j ≤ 20.
The limiting value of F[j + 1]
F[j]
is known as the Golden Ratio. It appears in
unexpected places
(see https://www.mathsisfun.com/numbers/golden-ratio.html scroll down
to ”FIbonacci Sequence”).
(c) Sketch the Fibonacci Spiral. The Fibonacci spiral is made up of quarter circles
(i.e. arc of a circle subtended by a 90o angle) passing through the diagonally
opposite vertices of squares that have sides in the Fibonacci sequence. Use the
functions you wrote in Lab 5 to draw the arc. The figure on the left, with the
squares, is to illustrate the drawing. The figure on the right is what your curve
should look like ( the first arc is drawn with the turtle facing East). To illustrate, each quarter circle arc is a different colour. The side lengths are scaled
by a factor of 5 (i.e. a square of side length ` will be 5 · ` in the drawing. Your
function goldenSpiral.py, takes a turtle as a parameter and have a default
parameter n = 10 for the number of arcs that make up your spiral.
Ex. of Spiral with squares drawn in Golden Spiral with n=10 & scale = 5