[Tutor] Interactive programming.
A.T.Hofkamp
a.t.hofkamp at tue.nl
Wed Jan 7 12:56:28 CET 2009
Kent Johnson wrote:
> On Wed, Jan 7, 2009 at 5:28 AM, A.T.Hofkamp <a.t.hofkamp at tue.nl> wrote:
>> 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.
>
> No, IDLE does not supply the ..., that is the source of the confusion.
>
> If you use the interpreter directly from a command/terminal window it
> will supply the ... continuation prompt but the IDLE shell will not.
Thank you Kent, I didn't know that.
The story stays the same, except that you don't get the "... " from Python.
That means that the second line and further are all shifted 4 positions to the
left, so you'd need to enter something like:
>>> i = 5
>>> j = 7
>>> if i <= j:
print 'nudge', 'nudge'
else:
print 'whatever'
I agree that this is highly confusing.
The best solution is probably to use the editor window instead, and save/run
your programs from there.
Sincerely,
Albert
More information about the Tutor
mailing list