-
-
Save harababurel/cfd10b9c51167acb93a7 to your computer and use it in GitHub Desktop.
Algebra exam grades faker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Nicely done