Hey, so for a project of mine we are asked to draw a face using instances of classes. I'm not very familiar with classes and I was wondering if anyone could explain to me why my code wont even open the turtle window. I'm also slightly confused as to how things get passed down through the code and if someone could help explain that, I could do the other classes.

import turtle
class circle():
    def __init__(self, fill = 1, color = "green"):
        self.fill = fill
        self.color = color

    def draw(self, x=0, y=0):
        goto(x,y)
        turtle.color(self.color)
        turtle.up()
        turtle.goto (0,-100)
        turtle.down()
        turtle.fill(self.fill)
        turtle.circle(100)
        turtle.goto(0,50)

Well firstly you were close with the code tags. It goes

[code=python]

[/code]

But if that is your full code then there are a couple of things that you need to do.

The first of which is instantiate it. This means that you have to create an instance of it. You do that by going like this:

c = circle()

Cool so not you have an instance the __init__ method will have been called (it is called the first time you instantiate the class) and now you can call the draw method:

c.draw(20,20)
c.draw(30,3)

So add those three lines of code to the end of your program and have a fiddle around with the minor details to get it better.

Hope that helps.

This article has been dead for over six months. Start a new discussion instead.