# Python 3: Turtle drawing a star

Page 1 of 1

## 7 Replies - 30714 Views - Last Post: 24 December 2014 - 02:49 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=360410&amp;s=731b8ac28316e4618da12faed14b7ba3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 The Chief

Reputation: 4
• Posts: 123
• Joined: 12-November 14

# Python 3: Turtle drawing a star

Posted 24 December 2014 - 10:47 AM

I'm trying to draw a star and I'm told that each angle is 36 degrees.

So here is my code

```import turtle

turtle.penup()
turtle.goto(0,0)
turtle.pendown()
i = 0
while i <= 5:
turtle.forward(100)
turtle.left(36)
i+=1
turtle.done()

```

but it draws half of a 12 sided polygon. If I increase the degrees to something like 150 it starts looking more like a star but it doesn't join up with the starting position.

What am I doing wrong? The star in the book has 5 sides and it says each angle is 36 degrees but that can't be possible? They look more like 150 degrees.

This post has been edited by The Chief: 24 December 2014 - 10:48 AM

Is This A Good Question/Topic? 0

## Replies To: Python 3: Turtle drawing a star

### #2 andrewsw

• Entwickler

Reputation: 6604
• Posts: 26,913
• Joined: 12-December 12

## Re: Python 3: Turtle drawing a star

Posted 24 December 2014 - 10:54 AM

I demonstrate drawing stars in my tutorial. Essentially, you turn 144 degrees, not 36.

This post has been edited by andrewsw: 24 December 2014 - 10:59 AM

### #3 The Chief

Reputation: 4
• Posts: 123
• Joined: 12-November 14

## Re: Python 3: Turtle drawing a star

Posted 24 December 2014 - 10:59 AM

I knew it was just a case of guessing the correct angle. although one problem, the star is upside down, it should actually look like this

but mine is upside down, I think it's to do with my starting position?

### #4 andrewsw

• Entwickler

Reputation: 6604
• Posts: 26,913
• Joined: 12-December 12

## Re: Python 3: Turtle drawing a star

Posted 24 December 2014 - 11:02 AM

Quote

I knew it was just a case of guessing the correct angle.

Not guessing I hope

Quote

I think it's to do with my starting position?

It is either

• the starting position
• the direction the turtle is facing,
• whether he should move first, or turn

### #5 The Chief

Reputation: 4
• Posts: 123
• Joined: 12-November 14

## Re: Python 3: Turtle drawing a star

Posted 24 December 2014 - 11:10 AM

I changed it to turn first and made the turtle turn right instead of left.

Thanks!

### #6 The Chief

Reputation: 4
• Posts: 123
• Joined: 12-November 14

## Re: Python 3: Turtle drawing a star

Posted 24 December 2014 - 12:08 PM

Also do you know how to make the turtle type the contents of a variable?

for example
```import turtle
x1,y1,x2,y2 = eval(input("Type in some coordinates, e.g (50,80,-10,40)"))

turtle.penup()
turtle.goto(x1,y1)
turtle.write("p1", x1,y1)
turtle.pendown()
turtle.goto(x2,y2)
turtle.write("p2", x2,y2)
turtle.done()

```

I get the error
```Traceback (most recent call last):
File "D:/Python Projects/Basics/DrawLine.py", line 6, in <module>
turtle.write("p1", x1,y1)
File "<string>", line 1, in write
File "D:\Python Interpreter\lib\turtle.py", line 3431, in write
end = self._write(str(arg), align.lower(), font)
AttributeError: 'int' object has no attribute 'lower'

```

so I'm assuming turtle.write can only write strings?

### #7 andrewsw

• Entwickler

Reputation: 6604
• Posts: 26,913
• Joined: 12-December 12

## Re: Python 3: Turtle drawing a star

Posted 24 December 2014 - 12:25 PM

Why guessing and assuming? If you want to use the write() method then look it up in the docs or other reference material and see what arguments it uses and requires.

### #8 baavgai

• Dreaming Coder

Reputation: 7262
• Posts: 15,142
• Joined: 16-October 07

## Re: Python 3: Turtle drawing a star

Posted 24 December 2014 - 02:49 PM

Two things. One, your while goes six, not five, steps. Why use a while? Two, you can make the turtle do the angle math if you're not up to braining. e.g.
```turtle.pendown()

# i = 0
# while i <= 5:
for i in range(5): # this actually goes 5 times, not 6
turtle.forward(100)
turtle.left(180) # point to your butt first, now it will work
turtle.left(36)
# i+=1
turtle.done()

```