Python Forum
Turtle Polygon drawing program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turtle Polygon drawing program
#1
Hello everyone, my name's Tim and I'm a teacher and guess what: I've run out of coding skills Huh

I'm going through the thinkcspy learning program to get a good grip on the foundations of python before I do really funky stuff with networks and robots and stuff.

I'm writing a polygon drawing program with the turtle module. Here's the code:
sides_choice = input("how many sides?")
sides = int(sides_choice)
print (sides)
length_choice = input("how long are the sides?")
length = int(length_choice)
print (length)
lines = input("what colour lines?")
print (lines)
fill = input("what colour fill?")
print (fill)

import turtle
wn = turtle.Screen()
bob = turtle.Turtle()

bob.color(lines)
bob.fillcolor(fill)
for polygon in range(sides):
    bob.fd(length)
    bob.left(((sides -2)*180)/sides)
My problem is with the last line. I'm pretty confident of the maths being correct because the formula for the total interior angles for a regular polygon is (n-2)*180 where 'n' is the number of sides. And then to get each individual corner angle you then divide the result of the last formula with n again.

But I'm not getting the result I should. I'm wondering if there's a syntax error with how I've laid out the arithmetic??
Any help is appreciated Smile
Reply


Messages In This Thread
Turtle Polygon drawing program - by tp_oz - Jul-23-2019, 12:33 PM
RE: Turtle Polygon drawing program - by ichabod801 - Jul-23-2019, 12:50 PM
RE: Turtle Polygon drawing program - by tp_oz - Jul-23-2019, 12:54 PM
RE: Turtle Polygon drawing program - by ichabod801 - Jul-23-2019, 01:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a turtle drawing from .txt file Noob101 20 9,051 Jan-29-2021, 04:13 PM
Last Post: nilamo
  Drawing wheels in a turtle woehh 1 1,916 Apr-23-2020, 02:58 PM
Last Post: deanhystad
  Divide a Python Turtle program into subprograms TurtleOHG 5 3,453 Mar-21-2020, 02:07 PM
Last Post: buran
  turtle polygon as specified by user input johneven 7 10,817 Mar-02-2019, 10:11 PM
Last Post: johneven
  How to hold a program in the turtle (Tic-Tac-Toe game assignment) kmchap 1 4,596 May-17-2018, 05:39 PM
Last Post: j.crater
  Turtle drawing Right Triangle Zatoichi 3 5,751 Feb-26-2018, 12:24 AM
Last Post: Zatoichi
  Help drawing circles with turtle songminguk 3 4,515 Dec-19-2017, 08:43 PM
Last Post: squenson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020