This is an old revision of the document!
flip.py
import random total = 0 for i in range(2000000000000000000): flip = random.randint(0, 1) 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/10000000000) == 0: print('%d %f' % (i, pi_estimate)) main()
walk.py
import random import math
x = 0 y = 0 for i in range(20000): flipx = random.randint(-1, 1) flipy = random.randint(-1, 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)
#Doug & Javascript 3
<!DOCTYPE html> <html> <head> <title>Bugs - Complete</title> <style> #bug { position:fixed; top: 200px; left: 200px; transition: width .5s, height .3s; cursor: url(cursor.png),crosshair; } #counter { background: #FFF; z-index: 6; position: fixed; left: 45%; width: 200px; bottom: 0; border: 1px solid #000; padding: 10px; font-size: 22px;} #counter p { text-align: right; } html {} </style> </head> <body> <img src="bug.png" id="bug" <div id="counter"><p>Your Score: <span id="scoreboard"> </span></p><p>Time Remaining: <span id="timer">30</span></p> </div> </body> </html>
#Notes
Slightly adjusted