python代写 python作业代写 python程序代写 代写python程序

python turtle程序代写, python turtle代写, turtle编程代做, python turtle代做

Python Programming for Scientists CSCI 2202 

Assignment 1, Due 18 Feb 2022 11:30 pm 

Note: Please put all your programs (titled ex n n = # of exercise) into a single folder titled: 

A1 your name, zip it and submit it through Brightspace. You may discuss the problems with 

anyone, but please do not copy/share/show code from/to each other. Acknowledge any help 

received (except that from the instructor and TA for the course). 

(1) 

In Lab 2, you made a program, using the turtle module, that could draw polygons 

of a user-specifified number of sides. Create a new program that draws the polygon, 

rotated a specifified 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 fifigure 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 di↵erent 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 flfloating 

point numbers is rare. 

1

(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 fifirst 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 breed

ing. 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 modifification of the above 

problem gives: 

F[0] = 0, F[1] = 1and F[j] = F[− 1] + F[− 2], n ≥ 

(a) Write program FibonacciSeq.py that prompts the user for a positive integer 

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?

You will need to refer to: 

https://docs.python.org/3/tutorial/datastructures.html for list meth

ods. 

(b) 

Make your program print compute the ratio: 

F[

+ 1] 

F

[j

for 2   20. 

The limiting value of 

F[

+ 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 90angle) passing through the diagonally 

opposite vertices of squares that have sides of lengths given by the Fibonacci 

sequence. Use the functions you wrote in Lab 6 to draw the arc. The fifigure 

on the left, with the squares, is to illustrate the drawing. The fifigure on the 

right is what your curve should look like ( the fifirst arc is drawn with the turtle 

facing East). To illustrate, each quarter circle arc is a di↵erent 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

京ICP备2025144562号-1
微信
程序代写,编程代写
使用微信扫一扫关注
在线客服
欢迎在线资讯
联系时间: 全天