repl.it
@NiclasOstlund/

Draw a square

Python (with Turtle)

No description

fork
loading
main.py
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
# The document at this uRL has a list of turtle commands: https://docs.google.com/document/d/1X9gMUBoXVh7ZJxy2CWDhjuQniv19PJ7i-txoVfDvyEM/edit?usp=sharing
import turtle

def draw_square(t, sz):
  """ Make turtle t draw a square of sz. """
  t.pendown()
  t.begin_fill()
  for i in range(4):
    t.forward(sz)
    t.left(90)
  t.end_fill()
  t.penup()

# Create turtle
alex = turtle.Turtle() 
# Set its colour (used for fill as well), pen colour
# and speed (0 = fastest)
alex.color('orange')
alex.pencolor('red') 
alex.speed(0)
# By default the pen is down so it has to be raised before 
# moving the turtle
alex.penup() 
alex.goto(50, 0)

draw_square(alex, 100)   
 
result
console
?