[Tutor] Why does loop duplicate?

Alan Gauld alan.gauld at btinternet.com
Thu Dec 17 04:16:15 EST 2015


On 16/12/15 19:37, Ken Hammer wrote:
>...  IDLE and Shell are Python 2.5.4 running on Windows 8.1.

How exactly are you running this?
Have you typed the code into a separate file using IDLE and then
run it via the Run menu?  Or are you importing the module at
the >>> prompt? Or are you typing it into the interactive
shell window? Or something else?

The reason I ask is that I don't get repeats, so either you
are running different code - possibly because of importing
it and then changing it but not reimporting - or the way
you run it is somehow causing the phenomenon.

> prefixes = 'JKLMNOPQ'   ###FAILS WITH REPEATS
> suffix = 'ack'
> suffixb= 'uack'
> 
> for letter in prefixes:
>     if letter == "O":
>         print letter + suffixb
>     if letter == "Q":
>         print letter + suffixb
>     else:
>         print letter + suffix
> 

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list