Skip to content

Instantly share code, notes, and snippets.

@rusucosmin
Forked from harababurel/x.py
Created November 21, 2015 20:32
Show Gist options
  • Save rusucosmin/9c554b90c1de9022f421 to your computer and use it in GitHub Desktop.
Save rusucosmin/9c554b90c1de9022f421 to your computer and use it in GitHub Desktop.
import re
from random import randint, choice
f = open('algebra.html', 'r')
g = open('algebra2.html', 'w')
updated = 0
sumSoFar = 0.0
modes = ['low', 'avg', 'high']
mode = choice(modes)
for line in f:
newLine = line
while 'td class="s11"><' in newLine:
if mode == 'low':
a, b = 0, 4
elif mode == 'avg':
a, b = 3, 7
else:
a, b = 6, 10
points = randint(a, b) / 10
sumSoFar += points
updated += 1
if updated % 5 == 0:
mode = choice(modes)
sumSoFar -= points # go back one addition
points = sumSoFar
sumSoFar = 0.0
newLine = newLine.replace('<td class="s11"><', '<td class="s11">%.1f<' % points, 1)
g.write("%s\n" % newLine)
f.close()
g.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment