Hi All
I am trying to learn Python and cannot get aroud this problem for the life of me.
I have generated a sript as follows, called xandy.py
def xandy (x,y):
if x < y:
print x, "is less than", y
elif x > y:
print x, "is greater than", y
else:
print x, "and", y, "are equal"
I cannot get it to work in the shell?
>>> x=5
>>> y=4
>>> xandy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'xandy' is not defined
>>> xandy (5,4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'xandy' is not defined
>>>
Thanks in anticipation

2 ways at least: you can type

>>> from xandy import xandy

and then use your function. The file must be in a place where python will find it (in a folder listed in your PYTHONPATH environment variable.
Second (and best) way, run python's built-in gui IDLE (look in the subfolder idlelib of your python library). When idle has started, choose to open your program in the file menu, then select RUN MODULE in the Run menu and your program will run in the shell.

Edited 7 Years Ago by Gribouillis: n/a

First of all chico2009, please enclose your code in proper tags, for more on that refer to this link.

Now, moving onto your question, the only thing you have to change is:

x=5
y=4
xandy(x,y)
This question has already been answered. Start a new discussion instead.