Commit f6b63c71d20e3bd9c226d1ab4a697a1b530574ac
1 parent
c7ca2f4e
Exists in
master
and in
1 other branch
changes to demo scripts
Showing
3 changed files
with
24 additions
and
24 deletions
Show diff stats
demo/questions/correct/correct-question.py
| @@ -3,24 +3,22 @@ | @@ -3,24 +3,22 @@ | ||
| 3 | import re | 3 | import re |
| 4 | import sys | 4 | import sys |
| 5 | 5 | ||
| 6 | -s = sys.stdin.read() | 6 | +msg1 = '''--- |
| 7 | +grade: 1.0 | ||
| 8 | +comments: Muito bem! | ||
| 9 | +''' | ||
| 10 | + | ||
| 11 | +msg0 = ''' | ||
| 12 | +grade: 0.0 | ||
| 13 | +comments: A resposta correcta é "red green blue". | ||
| 14 | +''' | ||
| 7 | 15 | ||
| 8 | -# set of words converted to lowercase lowercase | ||
| 9 | -answer = set(re.findall(r'[\w]+', s.lower())) | 16 | +s = sys.stdin.read() |
| 10 | 17 | ||
| 11 | -# correct set of colors | ||
| 12 | -rgb_colors = set(['red', 'green', 'blue']) | 18 | +answer = set(re.findall(r'[\w]+', s.lower())) # get words in lowercase |
| 19 | +rgb_colors = set(['red', 'green', 'blue']) # the correct answer | ||
| 13 | 20 | ||
| 14 | if answer == rgb_colors: | 21 | if answer == rgb_colors: |
| 15 | - # print(1.0) | ||
| 16 | - print(''' | ||
| 17 | - grade: 1.0 | ||
| 18 | - comments: Muito bem! | ||
| 19 | - ''') | 22 | + print(msg1) |
| 20 | else: | 23 | else: |
| 21 | - # print(0.0) | ||
| 22 | - print(''' | ||
| 23 | - grade: 0.0 | ||
| 24 | - comments: A resposta correcta é "red green blue". | ||
| 25 | - ''') | ||
| 26 | -exit(0) | ||
| 27 | \ No newline at end of file | 24 | \ No newline at end of file |
| 25 | + print(msg0) |
demo/questions/correct/correct-timeout.py
| @@ -5,7 +5,8 @@ import time | @@ -5,7 +5,8 @@ import time | ||
| 5 | 5 | ||
| 6 | s = sys.stdin.read() | 6 | s = sys.stdin.read() |
| 7 | 7 | ||
| 8 | -# generate timeout | 8 | +# sleep a lot of time to generate timeout during correction |
| 9 | time.sleep(100) | 9 | time.sleep(100) |
| 10 | 10 | ||
| 11 | +# probably this result will not be seen because the script will be interrupted | ||
| 11 | print(0.5) | 12 | print(0.5) |
demo/questions/generators/generate-question.py
| @@ -5,22 +5,23 @@ import sys | @@ -5,22 +5,23 @@ import sys | ||
| 5 | 5 | ||
| 6 | arg = sys.stdin.read() # read arguments | 6 | arg = sys.stdin.read() # read arguments |
| 7 | 7 | ||
| 8 | -a,b = (int(n) for n in arg.split(',')) | 8 | +a, b = (int(n) for n in arg.split(',')) |
| 9 | 9 | ||
| 10 | -q = ''' | 10 | +q = f'''--- |
| 11 | type: checkbox | 11 | type: checkbox |
| 12 | -text: | | ||
| 13 | - 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. | 12 | +text: | |
| 13 | + Indique quais das seguintes adições resultam em overflow quando se considera | ||
| 14 | + a adição de números com sinal (complemento para 2) em registos de 8 bits. | ||
| 14 | 15 | ||
| 15 | - Os números foram gerados aleatoriamente no intervalo de {0} a {1}. | 16 | + Os números foram gerados aleatoriamente no intervalo de {a} a {b}. |
| 16 | options: | 17 | options: |
| 17 | -'''.format(a,b) | 18 | +''' |
| 18 | 19 | ||
| 19 | correct = [] | 20 | correct = [] |
| 20 | for i in range(5): | 21 | for i in range(5): |
| 21 | x = randint(a, b) | 22 | x = randint(a, b) |
| 22 | y = randint(a, b) | 23 | y = randint(a, b) |
| 23 | - q += '- "`{} + {}`"\n'.format(x, y) | 24 | + q += f' - "`{x} + {y}`"\n' |
| 24 | correct.append(1 if x + y > 127 else -1) | 25 | correct.append(1 if x + y > 127 else -1) |
| 25 | 26 | ||
| 26 | q += 'correct: ' + str(correct) | 27 | q += 'correct: ' + str(correct) |