Turtle Ch4 Exercise 6

I have all the user inputs loading into the code correctly. But I want my turtle blue and I want my polygon filled red. Once I set my turtle blue, the polygon wont accept another value. Is that possible to get two separate colors?

Nevermind, I figured it out with the .color(variables), can take more than one input!

You may also want to look over the table at 4.9.

1 Like

Is the fill color just for the turtle shape (i.e. the arrow, circle etc…) or is it to fill in the polygon itself like a background color? I have a different color for the “tail” line and the turtle but the inside of the polygon is still white.

There are two color functions I’ve found so far alex.color(“red”), and begin_fill, end_fill, for the polygon. You can give the original .color() several color variables.

Awesome, i got it! Thanks!

assigning a variable value to the color method, e.g.,

is producing this error:
ExternalError: TypeError: instance is undefined on line 24

I requested user input for the value of the variable (shape_c) using input(…), then I tested it using a print(shape_c) and print(type(shape_c)). Both print commands returned exactly what I would have expected. However, when I try to use the variable as an argument in the .color() method, it generates the above error. “…undefined” doesn’t help much…


BTW, should I have posted this as a new question / thread / topic rather than a reply in the existing one???

Colors require string types i believe.

yes, and that’s what I’m getting; when I check the type of the variable shape_c it returns ‘str’

input on: shape_c=str (input(“something”))
Does that work for you?

That gives me:
ParseError: bad input on line 24 (NOTE: that’s where that code is sitting)
More importantly, what does it mean? I don’t recall that being covered.

I have no problem with the logic of the problem; it’s beating the syntax and the IDE into submission that is taking all my time

After getting all user inputs, I can get this far
turn = 360/sides (sides is supplied by the user; the division results in a ‘float’

Now it breaks down altogether:
fred.color(shape_c) (value supplied by user that tests to ‘str’; returns undefined error)
fred.fillcolor(fill_c) (value supplied by user that tests to ‘str’)

for i in range(0, sides, 1): (sides, supplied by user, tests out to an ‘int’)
fred.left(turn) (turn is defined above; IDE says there is no value there
fred.forward(length) (length, supplied by the user, tests out to an ‘int’; IDE says there is no value there)

What Scott wrote is assigning a user input to the variable “shape_c” and then passing that into the color parameter. But if you cut and pasted his code as is it would throw a parse error because the spacing is off in places. I THINK that’s what happened :thinking:

1 Like

What type of info is being entered by the user for the variable “shape_c”? Like it should be red, green, blue etc…right? if you’re trying to pass it in the color function? or are you asking the user for something different?

Why do you have 3 variables in the “for i in range:” statement?

Also, “sides” needs to be turned into an int if you are going to do 360/sides, and if you’re using sides in the range. I wasn’t trying to give you the code exactly as it should be entered, just the idea to get you in the right direction.

1 Like

shape_c = input(“What color do you want”)


ExternalError: TypeError: instance is undefined on line 24 (that’s where fred.color(shape_c) is

Maybe try putting shape_c in quotes like how you would if it was just: fred.color(“red”) …

Disregard…I regret to inform you that you have wasted time on a question where your fellow student was stoopid… I didn’t add the () after fred=turtle.Turtle or wn = turtle.Screen. Like I said…stoopid.

1 Like

It is all good! At least you will never forget now.

1 Like