generate-question.py 462 Bytes
#!/usr/bin/env python3.4

from random import randint


q = '''
type: checkbox
text: Indique quais das seguintes adições resultam em overflow quando se considera a adição de números com sinal (complemento para 2) em registos de 8 bits.
options:
'''

correct = []
for i in range(5):
    x = randint(11,120)
    y = randint(11,120)
    q += '- "`{} + {}`"\n'.format(x, y)
    correct.append(1 if x + y > 127 else -1)

q += 'correct: ' + str(correct)

print(q)