Please I am having challenges to write a code with notepad and then run it with IDLE 2.6 particularly when importing modules like turtle.

Here is an example:

here is python code :

# Programme pour dessiner une série de triangles équilatéraux de différentes couleurs en différent endroit.
from turtle import *                   	# Nous importons tous le module turtle
def triangle(hauteur, couleur):         # Nous allons construire le triangle équilatéral
        color(couleur)
        forward(hauteur)
        left(120)
        forward(hauteur)
        left(120)
        forward(hauteur)

reset()                                 # Effacons l'affichage graphique

f = int(raw_input('Hauteur du triangle'))       # hauteur de notre triangle
e = 1
while e < 6 :
        color = raw_input('Entrez la couleur')
        up()
        goto(e*f+50, f)
        down()
        triangle(f, color)
e = e + 1

I receive this error message:
Traceback (most recent call last):
File "D:\Logiciel\PYTHON\Exercices\TrianglesEqui.py", line 2, in <module>
from turtle import * # Nous importons tous le module turtle
File "D:\Logiciel\PYTHON\Exercices\turtle.py", line 2, in <module>
forward(120)
NameError: name 'forward' is not defined

Please what is it that I am not doing right?
Kind regards

Vermont

Your folder D:\Logiciel\PYTHON\Exercices contains a suspicious file turtle.py which is probably not the module turtle from python's lib-tk. So check this file, and rename it if necessary.

Python checks in the working directory first, and if you save one of your own files with a module name, you don't get the proper module.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.