 PROGRAMMING

# m9/ PYTHON REMEMBERS

Last update:   23-07-2021

### Turtle

p65 ! Python turtle (draw) module allows you to create images with turtle graphics. Create a window with small arrow that represents the turtle. # /var/www/python/test.py

import turtle
bob = turtle.Turtle()
print(bob)
turtle.mainloop()  # wait for user to do somethings

# sudo apt-get install python3-tk

p67 To move the turtle forward use fd() method. The argument of fd is in pixels, for lt() and rt() in degrees. # /var/www/python/test.py

import turtle
bob = turtle.Turtle()
print(bob)

bob.fd(100) # Look Here
bob.lt(90)
bob.fd(100)

turtle.mainloop()
... 2 lines 
Modify the program and draw a square. # /var/www/python/test.py

import turtle
bob = turtle.Turtle()
print(bob)

bob.fd(100)

bob.lt(90)
bob.fd(100)

bob.lt(90)
bob.fd(100)

bob.lt(90)
bob.fd(100)

turtle.mainloop()
... 6 lines 

### Loop

p69 ! The syntax of a for statement is similar to a function definition. The flow of execution runs through body and then loops back to the top. # /var/www/python/test.py

import turtle
bob = turtle.Turtle()
print(bob)

for i in range(4):
bob.fd(100)
bob.lt(90)

turtle.mainloop()
... 2 lines """
Write a function called square() that ...
takes a parameter named t, which is a turtle.
It should use the turtle to draw a square.

import turtle
bob = turtle.Turtle()
square(bob)
turtle.mainloop() """

# SOLUTION

???

solution code
Questions

A B C D E F
🔔
1/2