-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathnested.py
More file actions
68 lines (54 loc) · 1.79 KB
/
nested.py
File metadata and controls
68 lines (54 loc) · 1.79 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
CSci 127 Teaching Staff
February 2018, Updated for Spring 2025
A template for a program that draws nested triangles
Modified by: ADD YOUR NAME HERE
ADD YOUR EMAIL
"""
import turtle
def setUp(t, dist, col):
"""
Takes three parameters, a turtle, t, the distance, dist,
to move the turtle and a color, col, to set the turtle's color.
"""
t.penup()
t.forward(dist)
t.pendown()
t.color(col)
def triangle(t, length, scale):
"""
Takes two parameters: a turtle and a length.
The function does the following: if the length is greater than scale,
it repeats 3 times: moves forward that length, turns 120 degrees,
and calls triangle(t, length/2, scale).
"""
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### these are the only sections ###
### you change in this program. ###
###################################
def nestedTriangle(t, length, scale):
"""
Takes two parameters: a turtle and a length.
The function does the following: if the length is greater than scale,
it repeats 3 times: moves forward that length, turns 120 degrees,
and calls triangle(t, scale/2).
"""
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### these are the only sections ###
### you change in this program. ###
###################################
def main():
n = int(input('Enter length: '))
s = int(input('Enter scale: '))
tom = turtle.Turtle()
setUp(tom, -100, "darkgreen")
triangle(tom, n, s)
tess = turtle.Turtle()
setUp(tess, 100, "steelblue")
nestedTriangle(tess, n, s)
if __name__ == "__main__":
main()