1

This problem is common I think but tried searching the answers but nothing worked. So now I'm here asking you guys. So when I write the code below

import turtle


t = turtle.Pen()

for x in range(random_number):
    t.forward(x)
    t.left(random_number)

and run it by pressing F5 it always shows this error:

Traceback (most recent call last):
File "C:/Users/User/AppData/Local/Programs/Python/Python37-32/ss.py", line 1, in <module>
import turtle
File "C:/Users/User/AppData/Local/Programs/Python/Python37-32\turtle.py", line 2, in <module>
t = turtle.Pen()
AttributeError: module 'turtle' has no attribute 'Pen'

And I'm currently using Win7 and python v3.7.0 so pls help me if you can.

Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64
  • 1
    I don’t think the turtle module has a class named Pen. And that’s exactly what the error message is telling you. The question is: why did you expect this to work? Did you find a tutorial with code like this, or read something in the docs that suggested it? – abarnert Aug 25 '18 at 03:55
  • But this actually worked for my other classmates – newbie_coder Aug 26 '18 at 04:08
  • OK, it's a bit weird that your class is using an undocumented alias for `Turtle`… but it should work. – abarnert Aug 26 '18 at 04:44
  • The reason it doesn't work for you is that you created a file called `turtle.py`. So, when you `import turtle`, instead of getting the standard `turtle` module from the standard library, you're getting your own file, which doesn't have a `Pen` class. Just get rid of, or rename, that file. – abarnert Aug 26 '18 at 04:45
  • This is a very common problem that everyone runs into, and has a hard time debugging the first time, so I'm sure there's a good duplicate question with a complete answer; just let me find it. – abarnert Aug 26 '18 at 04:46

0 Answers0