-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgoldenRatio.py
More file actions
37 lines (29 loc) · 1.13 KB
/
goldenRatio.py
File metadata and controls
37 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import turtle
def fibonacci(position):
'''
Objective : To calculate fibonacci number at position 'position'
Input Variables :
position : Given position, the position at which fibonacci to be calculated.
Return Value : Corresponding fibonacci number at position 'position'
'''
# Approach : Recursion is used to find fibonacci number at position'position'.
if position == 0 or position == 1:
return 1
else:
return fibonacci(position-1) + fibonacci(position-2)
def drawCircle(number):
'''
Objective : To draw the golden ratio circle 'number' times.
Input Variables :
position : Given number, number of level it draws the circle.
Return Value : None.
'''
# Approach : Turtle package is used to draw circle, method used 'turtle.circle(...)'.
fibonacciList = []
for i in range(number):
fibonacciList.append(fibonacci(i))
for i in fibonacciList:
turtle.circle(i,90)
if __name__ == '__main__':
number = int(input("Enter the number: "))
drawCircle(number)