Reputation: 3
from turtle import *
wn = turtle.Screen()
wn.bgcolor(#0077AA)
t = turtle.Turtle()
#turtle
importing turtle
def square():
for i in range(10):
for j in range (4):
t.pendown()
t.forward(50)
t.right(90)
t.penup()
t.forward(50)
defining a function
def multi_square():
for k in range(10):
square()
t.right(90)
t.forward(50)
t.right(90)
t.forward(500)
t.right(180)
defining another function and calling a the first defined function in it
Upvotes: 0
Views: 165
Reputation: 365657
There are multiple errors in your code.
As iCodez points out, #0077AA)
is a comment; you need quotes to make a string.
If you do from turtle import *
, the classes and functions from turtle
can only be accessed with unqualified names, like Screen
; if you want to use qualified names like turtle.Screen
you need import turtle
.
You define two functions, but never call them, so your code won't do anything. You need to add a call to multi_square()
at the end.
Your multi_square
function draws one square, then moves all the way to the left edge of the screen and draws another (only partly-visible) one, then moves way off the edge of the screen and does nothing visible ever again. You need more sensible coordinates. Maybe you wanted to move 50, 50 instead of 50, 500?
I don't know whether this is a bug or a feature, but your square
function draws the same square 10 times in a row. I'll assume you wanted that to watch the turtle running around.
Putting that all together:
import turtle
wn = turtle.Screen()
wn.bgcolor('#0077AA')
t = turtle.Turtle()
def square():
for i in range(10):
for j in range (4):
t.pendown()
t.forward(50)
t.right(90)
t.penup()
t.forward(50)
def multi_square():
for k in range(10):
square()
t.right(90)
t.forward(50)
t.right(90)
t.forward(50)
t.right(180)
multi_square()
Upvotes: 3
Reputation:
You have to make the background color a string:
wn.bgcolor('#0077AA')
Otherwise, noting the #
, Python thinks that that is a comment.
Upvotes: 3