[Tutor] (no subject)

Gregory Morton tyetheczar at hotmail.com
Fri May 29 16:46:17 CEST 2009


I'm having a problem understanding how this code works in lesson 4.4 on the python tutorial. Can anyone explain it in easy-to-digest details? I kind of know what most of the stuff means, but I can't comprehend how it all works in unison. That, and I'm having a hard time understanding what break does.
for n in range(2, 10):
...     for x in range(2, n):
...         if n % x == 0:
...             print(n, 'equals', x, '*', n//x)
...             break
...     else:
...         # loop fell through without finding a factor
...         print(n, 'is a prime number')
...
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3Thanks for all your help,Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090529/d2309382/attachment.htm>


More information about the Tutor mailing list