REMEMBER PYTHON

MINTE9
2REMEMBER




Turtle

p65 ! Python turtle (draw) module allows you to create images with turtle graphics. Create a window with small arrow that represents the turtle.
 CodeCopy
# /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
... 6 lines
˄˄˄
p67 To move the turtle forward use fd() method. The argument of fd is in pixels, for lt() and rt() in degrees.
 CodeCopy
# /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()
... 8 lines
˄˄˄
Modify the program and draw a square.
 CodeCopy
# /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()
... 12 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.
 CodeCopy
# /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()
... 8 lines
˄˄˄
Task

 CompleteTask
"""
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    
No. 5   Conditional
CARD
04
32

        A B C D E F
🔔
1/2