Open in TheBrain

Loop Range While

<p>Jan 25, 2013 07:00 PM &#160;done with Sean on Jan 12 2013

&#160;

open &#160;2.7 IDLE (Python GUI)

&#160;

&#62;&#62;&#62; range(10)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

&#160;

[] denotes a list

&#160;

&#62;&#62;&#62; for x in range(10):

print x

0

1

2

3 ... 9

&#160;

&#62;&#62;&#62; bob = range(100)

&#62;&#62;&#62; bob

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]

&#62;&#62;&#62; alice = bob[3:80:10]

&#62;&#62;&#62; alice

[3, 13, 23, 33, 43, 53, 63, 73]

&#160;

&#62;&#62;&#62; spencer = [i2 for i in alice]

&#62;&#62;&#62; spencer

[9, 169, 529, 1089, 1849, 2809, 3969, 5329]

&#62;&#62;&#62; # note: [for i in alice: i2] &#160;does NOT WORK !

&#160;

&#62;&#62;&#62; bob =1

&#62;&#62;&#62;&#62;while bob &#60; 100:

&#160;&#160;bob=bob+1

&#160;print bob &#160;&#160;# then hit double enter

2 &#160;&#160;3 4 5 6 etc

&#160;

&#160;

&#160;

&#160;</p>

Attachments