While Loop

In [1]:
players = 7
while players < 9:
    print("need more players")
    players = players + 1
need more players
need more players

For Loop

In [6]:
## create set of 5 numbers, starting at 0
for i in range(5):
    print(i)
0
1
2
3
4

For Loop through list

In [8]:
myTeam = ['Duval', 'Votto', 'Cozart', 'Arroyo','Iglesias']
for p in myTeam:
    print(p)
Duval
Votto
Cozart
Arroyo
Iglesias

If Statement

In [15]:
import numpy as np
from numpy.random import randn

x = randn()
if x >= 1:
    print(str(x) + "is greater than or equal to 1")
else:
    print(str(x) + "is less than 1")
2.03054391266is greater than or equal to 1

Law of large numbers example. 1 standard deviation = 68.2%, randn function will give us normally distributed random number. lets test

In [27]:
import numpy as np
from numpy.random import randn
n=50000
ctr = 0

for i in randn(n):
    if i < 1 and i > -1:
        ctr = ctr + 1
        

print(ctr/float(n))
0.68296