I have a project for which I need to use turtle. I'm very new to python, and our teacher didn't really explain how to use turtle. What's the basic format I need to use to draw a polygon? I have to define a function, polygon(), and run it with two parameters as: polygon(sides, length). Do I import turtle first? Do I use for loops? I don't need someone to do the project for me; I just have absolutely no idea how turtle works and where to start. HELP please!!!!

Thanks!

Recommended Answers

All 2 Replies

Yes, you would need to import turtle. Here's a good place to start: docs.

And an excerpt from that site:

Because [turtle] uses Tkinter for the underlying graphics, it needs a version of python installed with Tk support.

So make sure you've got a more recent version of python.

Finally, a typical for loop:

for x in [1,2,3,4,5]:
    print x

Instead of a hard list you could use range(1,6) or better yet xrange(1,6); however the above example gives you a better idea of what's happening. Try typing that into your favorite Python interpreter to see what happens.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.