for x in range (360):
The above code is problem.when I try to run.I don’t understand. Please help
Ok first of all, your list of colors is “colours” and not “color” when you use it. Notice you put a “u” in the name. Second, pen returns a dictionary of values about the pen. You draw with “turtle” not “pen” like you do when set “t” to the pen. Functions like pencolor, forward and left are done with the turtle module itself. Below is your program with these changes put in place…
import turtle colours=['red','purple','blue','green','yellow','orange'] turtle.bgcolor('black') for x in range(360): turtle.pencolor(colours[x%6]) turtle.forward(x) turtle.left(59)
As you can see from the code, we made sure that we used the right name of the colour list.Second we are using methods from the “turtle” module. We change the pen color, then we move the turtle down and left while in the range.
This program makes a multicolored hex shape that is nice.
Thank you for reply.I am start learning a book call"tech your kids to code"by Bryson Payne.those code found in.sir I am currently using "qpython"and your codes give an error.please check it
It would be helpful if you told us what the error message said!
@Martyr2’s code works fine for me using the official version of Python on Windows.
This is a different script from the one you originally showed and the image you’ve posted doesn’t show the error you say is reported.
I update the screen shot.Please take a look
you sure you’ve copied the code correctly? look again…
Again the screenshot is trying to use “t” which is the returned dictionary from Pen(). This is not correct. Please look at the code I have shown you where you use “turtle” instead. I encourage you cut and paste my code into your program (making sure to ident as required) and try that. This code works and has been tested by me.
t = turtle.Turtle() instead of .Pen(), which will then return the turtle object, and the rest of the code works as-is.
I try everything but not working in "qpython "app.Attribute issue in line 7
I think you’ll need to post your current code and tell us which is line seven if you want anyone to help with that.
for x in range (360):
t.pencolor (colors[‘x%6’]): this
I may be missing something, but that just looks like the same code you posted in your OP. Did you not try the solutions which have already been offered to you?
There are differences in the code. But why are you posting it? Does it ork? Doesn’t it work? If it doesn’t work, what is the result you are getting that you don’t expect?
I get the feeling that you are not listening to what the people here are telling you. Lets review…
- Your list is named “colours” yet you use “colors” which is missing the “u”
- Next, turtle.Pen is not the same as turtle.pen. Python is case sensitive!
- You draw using turtle module directly or, as pointed out, turtle.Turtle(). This means your reference to pen is just to get the pen details, not for drawing.
Again, I suggest you go back to my fully working demo program, try that out and get it to work, then you can customize it little bit by little bit until you get it working how you want it.
I do follow all instructions but I am faild.attribute issue
So who’s instructions did you follow,
Martyr’s in post #2 when he told you to replace the references to t with the ones for turtle, or mine in post #10 when I told you you could replace the reference to Pen with one to Turtle?
Module name not found "
from turtle import* turtle.pensize (2) turtle.bgcolour('skyblue') turtle.speed (0) for i in range (6): colours=['red', 'purple','blue','green','yellow', 'orange'] turtle.color (colours) turtle.circle (100) turtle.left (10) turtle.hideturtle () for x in range (360): turtle.Turtle (colours[x%6]) turtle.forward(x) turtle.left(59)