[Tutor] Interactive programming.
A.T.Hofkamp
a.t.hofkamp at tue.nl
Wed Jan 7 11:28:29 CET 2009
WM. wrote:
> Norman Khine wrote:
>> >>> i = 5
>> >>> j = 7
>> >>> if i <= j:
>> ... print 'nudge', 'nudge'
>> ... else:
>> ... print 'whatever'
>> ...
>> nudge nudge
>> >>>
> Yes, I understand how your program works. What I do not understand is
> how you got it. My program came out in IDLE as you see it. No ...,
> different indentation, an error message before I could add the else
> alternative. (Which, as a Pythonista, one should know, is "Wink-wink".)
In IDLE in the window with the ">>>" prompt:
After the colon at the 'if' line, you press ENTER (ie you tell Python 'the
line has ended here').
The interpreter then supplies the "..." to denote that you are entering a
multi-line statement.
You then continue entering the next lines (with some indenting for both
branches!!), pressing ENTER after each line.
At the end (just above the "nudge nudge" output), Python also gives a "..."
prompt, to give you the option to enter more statements under the last print.
Since you don't have any more statements, just press ENTER (saying, 'I am
finished').
Then Python will execute the complete if statement (and one of the branches),
and output the result.
The normal approach however for entering a program is to use an editor window.
Click on 'new file' somewhere in IDLE (I am not an IDLE user nor do I have the
program around, so I cannot give you more precise directions unfortunately),
and enter the Python program without the ">>>" and "..." stuff at the start of
the line.
Once you are finished, save it, and press 'run' (it is in a menu somewhere if
I remember correctly).
Then the Python interpreter will run all statements in the file.
With this approach you can also load (and run) previous made programs (which
is a quite useful feature, I might add :) ).
(Instead of 'new file', use 'load file' or 'edit file').
Good luck,
Albert
More information about the Tutor
mailing list