This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| slush:codetalkers [2017/05/19 14:21] – oemb1905 | slush:codetalkers [2018/05/20 01:29] (current) – removed oemb1905 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | flip.py | ||
| - | import random | ||
| - | total = 0 | ||
| - | for i in range(2000000000000000000): | ||
| - | flip = random.randint(0, | ||
| - | total = total + flip | ||
| - | average = total / (i + 1) | ||
| - | print(i, flip, total, average) | ||
| - | | ||
| - | pi.py | ||
| - | import random | ||
| - | def main(): | ||
| - | N_sq = 0 | ||
| - | N_circ = 0 | ||
| - | n_iterations = 10000000000 | ||
| - | for i in range (n_iterations): | ||
| - | x = random.random() * 2 - 1 | ||
| - | y = random.random() * 2 - 1 | ||
| - | N_sq = N_sq + 1 #Always in square | ||
| - | if x*x + y*y < 1: | ||
| - | N_circ = N_circ + 1 | ||
| - | pi_estimate = 4.0 * float(N_circ) / float(N_sq) | ||
| - | if i % (n_iterations/ | ||
| - | print(' | ||
| - | main() | ||
| - | |||
| - | walk.py | ||
| - | |||
| - | import random | ||
| - | import math | ||
| - | |||
| - | x = 0 | ||
| - | y = 0 | ||
| - | for i in range(20000): | ||
| - | flipx = random.randint(-1, | ||
| - | flipy = random.randint(-1, | ||
| - | x = x + flipx | ||
| - | y = y + flipy | ||
| - | r = math.sqrt(x*x + y*y) | ||
| - | print(i, x, y, r) | ||
| - | |||
| - | General Instructions (Taken from Comments Section on old Code Talkers Classroom) | ||
| - | |||
| - | {{: | ||
| - | |||
| - | {{: | ||
| - | |||
| - | |||
| - | |||