Skip to content

Instantly share code, notes, and snippets.

@harababurel
Last active June 29, 2016 16:42
Show Gist options
  • Save harababurel/cfd10b9c51167acb93a7 to your computer and use it in GitHub Desktop.
Save harababurel/cfd10b9c51167acb93a7 to your computer and use it in GitHub Desktop.
Algebra exam grades faker
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()
@rusucosmin
Copy link

Nicely done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment