Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turtle Problem
#1
I'm drawing a polygon in which every side of that polygon should get a random color, that means that for every side the turtle should get a different color, this is my code:
import turtle
import random
r = 0.0


def cpolygon(n, size, colors):
	angle = 360/n 
	r = random.randint(25, 160)
	for i in range(n):
		turtle.pencolor(str(r))
		turtle.forward(100)
		turtle.left(angle)
	turtle.mainloop()

cpolygon(8, 100, r)
And this is the error:

Error:
turtle.TurtleGraphicsError: bad color string: 98
Help?
Reply


Messages In This Thread
Turtle Problem - by OmarSinno - Sep-26-2017, 07:31 AM
RE: Turtle Problem - by buran - Sep-26-2017, 07:44 AM
RE: Turtle Problem - by OmarSinno - Sep-26-2017, 07:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Problem installing turtle MasterJediKnight7 17 25,145 Mar-18-2024, 10:22 AM
Last Post: bmohamadyar313
  Begginer problem with turtle Damien_X 1 2,180 Aug-25-2020, 11:23 AM
Last Post: GOTO10
  Nested while loop problem + turtle DreamingInsanity 3 3,070 Jul-06-2019, 02:01 PM
Last Post: DreamingInsanity
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,275 Feb-06-2019, 01:25 AM
Last Post: woooee
  Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. BertyBee 3 5,763 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

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