8

Does anybody have any idea why this code doesn't work?

import turtle
test = turtle.Turtle()
test.color("orange")
test.pensize(5)
test.shape("turtle")
test.forward(100)

I use python 3.8

Community
  • 1
  • 1
Sahil Forough
  • 81
  • 1
  • 1
  • 4
  • This works in Python2.7 but not in Python3.7. I haven't found the exact reason why yet. What version of Python are you using? – Rusty Robot Mar 01 '20 at 22:36
  • 1
    the latest version (3.8) – Sahil Forough Mar 01 '20 at 22:38
  • 2
    How did you get Python 8.3? –  Aug 31 '20 at 23:44
  • 1
    Does this answer your question? [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – ggorlen May 23 '21 at 01:04

2 Answers2

47

You've made a common error that I happended to also make when I was investigating your question.

I assume you have your code written in a file called 'turtle.py'? When you import turtle, it imports your file, not the turtle library.

Rename your file to something other than turtle.py, and your code should run fine.

Here is the result when I renamed my file from turtle.py to turtle2.py.

Turtle

Rusty Robot
  • 1,525
  • 2
  • 12
  • 28
1

You need to end the loop that draws on the screen, by typing :

turtle.done()
Ann Zen
  • 25,080
  • 7
  • 31
  • 51
ayoub
  • 11
  • 1