Previous Lecture Complete and continue  

  Lesson 8: Looping Squares

28 comments
PaRuSch
Going more and more fancy.
https://repl.it/FKxr/0
Sebastian Gomez
https://repl.it/EyXR/0
Andres felipe Mora Guerrero
yoo thats so coool! nice
Aman Tyagi
great job man! you're not a beginner, are you?
Ali
Thats cool :)
Sebastian Gomez
Thank you, Ali!
Andrej Radojcic
When i do this it just draws 4 squares in same position. Then i tried to write this(don't pay attention to these weird words it's Serbian):
for nesto in range(4):
square(100, 90)
kvadrat.right(90)
kvadrat.forward (0.5)

And every time i don't get same 4 squares as you ( i tried to change kvadrat.forward many times but any of them isn't same as yours)
Aman Tyagi
# hey Andrej Radojcic, now your code is working
import turtle

kvadrat = turtle.Turtle()

def sqaure(length, angle):
kvadrat.forward(length)
kvadrat.right(angle)
kvadrat.forward(length)
kvadrat.right(angle)
kvadrat.forward(length)
kvadrat.right(angle)
kvadrat.forward(length)



for i in range(2):
sqaure(50, 90)
sqaure(50, 90)

turtle.done()
Praneeth
import turtle
a = turtle.Turtle()
def polygon(length , angle):
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)
a.forward(length)
a.right(angle)

polygon(25 , 90)
a.forward(100)
polygon(25 , 45)

shane
import turtle
my_turtle = turtle . Turtle()
def square(length,angle):



my_turtle.forward(length)
my_turtle.left(90)
my_turtle.forward(length)
my_turtle.left(90)
my_turtle.forward(length)
my_turtle.left(90)
my_turtle.forward(length)


for i in range(4):

square(100, 90)


Billy Harper
Why do my squares keep coming out side by side instead of stacking like yours do? I'm missing something but I can't figure out what.
Roshan Ali
I too... :(
Billy Harper
Hey man, I figured out what I was doing wrong. I had two extra lines of codes when defining 'square'. Not sure how it happened but I removed them and hey presto it worked. Maybe you have done the same?
Ali
can u show me the code u used ?
Billy Harper
Sure...

https://repl.it/Etkz/4

you actually helped me there also as I remade the code again without watching the video. :)
Darren Ong
import turtle
a = turtle.Turtle()
a.speed(0)

def square(length, angle):
for i in range(4):
a.forward(length)
a.right(angle)

for i in range(360):
square(100, 90)
a.right(1)

JUST AMAZING!
Ereatara Kokiri
loops
for e in range(4):
square(100)
David Žiković
import turtle

my_turtle = turtle.Turtle()

def square1(lenght,angle):
my_turtle.forward(lenght)
my_turtle.left(angle)

def square2(lenght,angle):
my_turtle.forward(lenght)
my_turtle.right(angle)

for s in range(5):
square1(50,60)

for s in range(6):
square2(50,60)

square2(50,60)

for s in range(5):
square1(50,60)

my_turtle.left(120)

for s in range(6):
square1(50,60)

square1(50,60)

for s in range(6):
square2(50,60)

my_turtle.right(120)

square2(50,60)

for s in range(7):
square1(50,60)

for s in range(6):
square2(50,60)
Hatim Elsadig Elamin Elhag
https://repl.it/EwjD/0
Diwaker Thakur
import turtle
my_turtle = turtle.Turtle()

def tringle(length, angle):
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
for i in range(10):
tringle(100, 60)
#try this
Anthony Davis
import turtle
j = turtle.Turtle()
def square(length, angle):
j.forward(length)
j.left(angle)
j.forward(length)
j.left(angle)
j.forward(length)
j.left(angle)
j.forward(length)
square(50, 90)
for i in range(4):
square(50, 90)
for i in range(4):
square(100, 90)
for i in range(4):
square(150,90)
for i in range(4):
square(200, 90)
# Im really starting to like this!!!
Robert Spina
import turtle

my_turtle = turtle.Turtle()
def square(length, angle):
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)
my_turtle.right(angle)
my_turtle.forward(length)

for i in range(8):

square(25, 120)
Tim Lange
import turtle

x = turtle.Turtle()

y = x.forward
z = x.right
u = x.left

def crazy(length, angle, anglee):

y(length)
z(angle)
y(length)
u(anglee)
y(length)
z(angle)
y(length)
u(anglee)
y(length)
z(angle)
y(length)
u(anglee)
y(length)
z(angle)
y(length)
u(anglee)
y(length)
z(angle)
y(length)
u(anglee)
y(length)
z(angle)
y(length)
u(anglee)
y(length)
z(angle)
y(length)
u(anglee)
y(length)
z(angle)
y(length)
u(anglee)
y(length)
z(angle)
y(length)
u(anglee)

for i in range(3):
crazy(50, 90, 45)

You'll get a pretty crazy thing.
Anidhito Irmandharu
import turtle

Avant = turtle.Turtle()

def square(xlength ,turn):
Avant.forward(xlength)
Avant.right(turn)
Avant.forward(xlength)
Avant.right(turn)
Avant.forward(xlength)
Avant.right(turn)
Avant.forward(xlength)

# This is A Single
# Flower Petal

#square(200 ,90)
#Avant.right(120)
#square(150 ,90)
#Avant.right(120)

#-----------------

for flowerpetal in range(6):
square(200 ,90)
Avant.right(120)
square(150 ,90)
Avant.right(120)

Same flower , but less lines :)
Lyubomir Ivelinov Petrakiev
hmmm so I was thinking, wouldn't be loops useful to simplify your square?

For example, the basic turtle we learned:

import turtle
my_turtle = turtle.Turtle()
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)

Would be simplified to:

import turtle
my_turtle = turtle.Turtle()
for i in range(4):
my_turtle.forward(100)
my_turtle.left(90)

And the definition:

import turtle
my_turtle = turtle.Turtle()
def square(length, angle):
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)
my_turtle.left(angle)
my_turtle.forward(length)

Would be simplified to:

import turtle
my_turtle = turtle.Turtle()
def square(length, angle):
for i in range(4):
my_turtle.forward(length)
my_turtle.left(angle)

Wouldn't that be useful? I'm not sure but I tried it and the code worked...
Jamie
Ok so I am now a little confused with why when in range of 4 it makes 4 squares of the size value given but 1000000 just over lapped. is it because its to biga number. I pictured like the page would look like graph paper or something.
Michael Simiyu
i cant continue
Rafeh Qazi
Why not?