error explanation

M

Mac Wood

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
 
G

Gary Herron

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:

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
 
C

Christos TZOTZIOY Georgiou

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

remove the time.py line (it's supposed to name the following lines, not
to be included with them :)
 
S

Steve Holden

Mac Wood said:
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:

Input a rate and a distance
Rate:5
Distance:10
Time: 2
Thanks for your help

Try using raw_input() rather than input()

regards
 
E

Erik Max Francis

Steve said:
Try using raw_input() rather than input()

That definitely will not work. That will just result in him trying to
preform arithmetic with strings instead of numerics.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,342
Members
48,018
Latest member
DelilahDen

Latest Threads

Top