Running python on unix

Grant Edwards grante at visi.com
Fri Mar 28 17:03:54 EST 2003


In article <cb172e47.0303281345.56b16f9b at posting.google.com>, kpatrick1979 wrote:

> I am a brand new user learning python for a programming languages
> class.  I am trying to use the practice tutorial to mimic the
> following if-statement exercise:
> 
>>>> x = int(raw_input("Please enter an integer: "))
>>>> if x < 0:
> ...      x = 0
> ...      print 'Negative changed to zero'
> ... elif x == 0:
> ...      print 'Zero'
> ... elif x == 1:
> ...      print 'Single'
> ... else:
> ...      print 'More'
> ...
> 
> However, after I enter the first line of code (i'm using the Python
> command line programming that you can get from the web) I immediately
> get the "Please enter an integer" line

The code is being executed as you type it in.  You should be
able to provide the input, then enter the rest of the code.
That's a pain, though.

> -- it doesn't permit me to type the rest of the code.

Sure it does, but it wants you to satisfy the raw_input() call
first.

> Does anyone know a better way for me to try and do this
> program?

Put the text of the program into a file using whatever text
editor you like.  Let's say the filename is example.py.

Then run the program like this from the shell prompt:

$ python example.py

-- 
Grant Edwards                   grante             Yow!  .. I want FORTY-TWO
                                  at               TRYNEL FLOATATION SYSTEMS
                               visi.com            installed within SIX AND A
                                                   HALF HOURS!!!




More information about the Python-list mailing list