# Lesson 8: Star(s)

This lesson learns are based on Python book page 90-97

# Tools

https://trinket.io/ (opens new window)

# Lesson Leans

# Function Argument(s)

main.py

print(1+2)
print(4+5)
1
2
output
3
9
1
2

main.py

def find_sum(a,b):
    print(a+b)

find_sum(1, 2)
find_sum(4, 5)
1
2
3
4
5
output
3
9
1
2

# Fills the color

main.py

from turtle import *

my_turtle = Turtle()

def rect():
    for i in range(4):
        my_turtle.forward(50)
        my_turtle.left(90)

rect()
1
2
3
4
5
6
7
8
9
10
output

image

# Add line color

main.py







 







from turtle import *

my_turtle = Turtle()

def rect():
    my_turtle.color("#fcba03")
    for i in range(4):
        my_turtle.forward(50)
        my_turtle.left(90)

rect()
1
2
3
4
5
6
7
8
9
10
11
12
output

image

# Fills the color

main.py







 
 



 



from turtle import *

my_turtle = Turtle()

def rect():
    my_turtle.color("#fcba03")
    my_turtle.fillcolor("#32a852")
    my_turtle.begin_fill()
    for i in range(4):
        my_turtle.forward(50)
        my_turtle.left(90)
    my_turtle.end_fill()

rect()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
output

image

# Create a Star!





 

 





from turtle import *

my_turtle = Turtle()

def star(n_point):
    angle = 180 - (180/n_point)
    for i in range(n_point):
        my_turtle.forward(50)
        my_turtle.right(angle)
  
star(5)
1
2
3
4
5
6
7
8
9
10
11
output

image











 
 
 
 
 
 
 
 
 


 


 

 

 


from turtle import *

my_turtle = Turtle()

def star(n_point):
    angle = 180 - (180/n_point)
    for i in range(n_point):
        my_turtle.forward(50)
        my_turtle.right(angle)

def move_pen_to(x, y):
    my_turtle.penup()
    my_turtle.goto(x, y)
    my_turtle.pendown()

def move_pen_forward(distance):
    my_turtle.penup()
    my_turtle.forward(distance)
    my_turtle.pendown()    


move_pen_to(-100,100)
star(5)
my_turtle.right(30)
move_pen_forward(80)
star(7)
move_pen_forward(80)
star(9)
move_pen_forward(80)
star(11)
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
output

Image

# Add the color!





 





















 


 

 

 

from turtle import *

my_turtle = Turtle()

def star(n_point, line_color, fill_color):
    angle = 180 - (180/n_point)
    my_turtle.color(line_color)
    my_turtle.fillcolor(fill_color)
    my_turtle.begin_fill()
    for i in range(n_point):
        my_turtle.forward(50)
        my_turtle.right(angle)
    my_turtle.end_fill()

def move_pen_to(x, y):
    my_turtle.penup()
    my_turtle.goto(x, y)
    my_turtle.pendown()

def move_pen_forward(distance):
    my_turtle.penup()
    my_turtle.forward(distance)
    my_turtle.pendown()    


move_pen_to(-100,100)
star(5,"#fcba03","#32a852")
my_turtle.right(30)
move_pen_forward(80)
star(7,"#F626B5","#3B1780")
move_pen_forward(80)
star(9,"#B664A0","#82CD21")
move_pen_forward(80)
star(11,"#55483E","#EC6091")
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
output

Image