+ 1

this is how to.create a square in python

import turtle my_square=turtle.Turtle() my_square.forward(90) my_square.left(45) my_square.forward(90) my_square.left(45) my_square.forward(90) my_square.left(45) my_square.forward(90) my_square.left(45)

19th Jun 2017, 5:00 PM
Karthick Raj
Karthick Raj - avatar
3 Respuestas
+ 2
and this is Question & Answer section!!! Besides, your code is not very elegant. Use a loop to shorten your code.
19th Jun 2017, 5:14 PM
Amarie
+ 1
import turtle my_octagon=turtle.Turtle() i = 0 while i < 8: my_octagon.forward(90) my_octagon.left(45) i += 1
19th Jun 2017, 5:33 PM
Tim
+ 1
@Tim your code is fine. :) You could use a for loop instead of while loop, because you don't need the i inside the loop. And the declaration my_octagon is not necessarily when you just want to draw one figure. octagon: import turtle for i in range(8): turtle.forward(100) turtle.left(45) square: import turtle for i in range(4): turtle.forward(100) turtle.left(90)
19th Jun 2017, 10:06 PM
Amarie