error explanation

Gary Herron gherron at islandtraining.com
Mon Sep 29 18:04:32 EDT 2003


On Monday 29 September 2003 02:45 pm, Mac Wood wrote:
> Could someone please explain this error message:
>
> Traceback (most recent call last):
>   File "C:\Python23\time.py", line 1, in -toplevel-
>     time.py
> NameError: name 'time' is not defined
>
> I tried entering the following example:
>
> time.py
> #This programs calculates rate and distance problems
> print "Input a rate and a distance"
> rate = input("Rate:")
> distance = input("Distance:")
> print "Time:",distance/rate
>
> which according to the tutor should have run as this:
> > python times.py
>
> Input a rate and a distance
> Rate:5
> Distance:10
> Time: 2
> Thanks for your help


The line "time.py" is not meant to be a python statement, but is the
name of the file whose contents are the succeeding lines.  Once you
get the file named "time.py" with this contents

#This programs calculates rate and distance problems
print "Input a rate and a distance"
rate = input("Rate:")
distance = input("Distance:")
print "Time:",distance/rate

then you can run the file with
  python time.py

Gary Herron







More information about the Python-list mailing list