while Loops

Ben Finney ben+python at benfinney.id.au
Wed Jun 22 00:02:03 EDT 2016

Elizabeth Weiss <cake240 at gmail.com> writes:

> Why is one of the results 5 since i=i+1?

What do you think ‘i = i + 1’ means? (Asking because your idea of what
that means may be affecting how you expect the loop to behave.)

> Should the maximum result be 4 since 4 +1=5?

Try “thinking like the computer”: perform the steps yourself, reading
each statement as though you are the computer. Keep a pad and pencil at
hand, and make notes on what changes as you go through. See what
you-as-computer actually emit onto the paper, and see whether that
matches what the Python session produces.

 \      “The difference between a moral man and a man of honor is that |
  `\   the latter regrets a discreditable act, even when it has worked |
_o__)                   and he has not been caught.” —Henry L. Mencken |
Ben Finney

More information about the Python-list mailing list