Loops

Lesson 10: For loops and While loops:

Solution to get rich scheme and also infecting the planet.

Algebraic Solution:

if n=5 let S equal the sum of the series
S=1+2+4+8+16
S=1+2(1)+2(2)+2(4)+2(8)
S=1+2(1+2+4+8)
S=1+2(S-tn)
where tn is the nth term
S=1+2S-2tn
Collect S terms
2tn-1=S
But the next term in the series, tn+1 is equal to 2tn
So when we sub this in it becomes
tn+1 -1 =S
Hence, the sum of the series is equal to the next term in the series minus 1.

Lesson 11: random module and guessing computer side

Note: round() in python3

The round function has changed behavior from python2 -> python3.

>>> round(5.5)
6

but

>>> round(6.5)
6

Notice: python3 rounds floats to the nearest even integer.