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.
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!
HmmmâŚ
assigning a variable value to the color method, e.g.,
fred.color(shape_c)
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âŚ
Thoughts/observations/suggestions???
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â))
fred.color(shape_c)
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
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.
shape_c = input(âWhat color do you wantâ)
red
print(shape_c)
red
print(type(shape_c))
âstrâ
fred.color(shape_c)
fred.forward(50)
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.
It is all good! At least you will never forget now.