-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex3.py
More file actions
42 lines (33 loc) · 640 Bytes
/
ex3.py
File metadata and controls
42 lines (33 loc) · 640 Bytes
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
38
39
40
41
__author__ = 'student'
import turtle
turtle.speed(20)
def koch(l, n):
assert n >= 0
assert l >= 0
turtle.shape('turtle')
if n == 0:
turtle.forward(l)
return
for i in range(n):
koch(l/3, n-1)
turtle.left(60)
koch(l/3, n-1)
turtle.right(120)
koch(l/3, n-1)
turtle.left(60)
koch(l/3, n-1)
return
def snowflake(l, n):
assert n >= 0
assert l >= 0
koch(l, n)
turtle.right(120)
koch(l, n)
turtle.right(120)
koch(l, n)
turtle.right(120)
return
l = 200
n = int(input())
snowflake(l, n)
turtle.mainloop()