How hard can this be?
Pieter Claerhout
Pieter_Claerhout at CreoScitex.com
Mon May 21 11:17:01 EDT 2001
I think you're missing a small part here:
>>> import math
>>> if x > 0:
... print "x is positive"
...
Traceback (innermost last):
File "<stdin>", line 1, in ?
NameError: x
>>>
If you just type in this in the Python interpreter, it doesn't know yet
about the variable x, because it doesn't exist yet. You should do something
like:
>>> import math
>>> x = 2
>>> if x > 0:
... print "x is positive"
...
x is positive
>>>
PS: you can even skip the import of math, because it is not even used in the
example shown above.
Cheers,
Pieter
Pieter Claerhout - Application Support
CreoScitex Europe - www.creoscitex.com
-----Original Message-----
From: Patrick Kirk [mailto:pknews at kirks.net]
Sent: Monday, May 21, 2001 5:13 PM
To: python-list at python.org
Subject: How hard can this be?
if x > 0:
print "x is positive"
You would think anyone could enter that but I can't. I get the following:
>>> import math
>>> if x > 0:
... print "x is positive"
...
Traceback (innermost last):
File "<stdin>", line 1, in ?
NameError: x
>>>
I've tried creating a .py file saying:
if x > 0:
print "x is positive"
and importing it but that doesn't work either.
>>> import a
Traceback (innermost last):
File "<stdin>", line 1, in
File "a.py", line 1
if x > 0:
^
SyntaxError: invalid syntax
The worrying thing is that this is copied directly from the tutorial so I
may well be off to Alan gould's site shortly. But is there something
obvious that I'm missing?
Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list