Commit 35a9e63d9a0c4ea4ffe85fe0226f1a39e8867f98

Authored by Miguel Barão
1 parent 14f8e674
Exists in dev

change demo/math/addition

demo/math/addition/addition-two-digits.py
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -#!/usr/bin/env python3  
2 -  
3 -import random  
4 -import sys  
5 -  
6 -a = int(sys.argv[1])  
7 -b = int(sys.argv[2])  
8 -  
9 -x = random.randint(a, b)  
10 -y = random.randint(a, b)  
11 -r = x + y  
12 -  
13 -print(f'''---  
14 -type: text  
15 -title: Adição de números com 2 algarismos  
16 -text: |  
17 - Qual o resultado da soma ${x}+{y}$?  
18 -correct: ['{r}']  
19 -solution: |  
20 - O resultado é {r}.''')  
demo/math/addition/addition.py 0 → 100755
@@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
  1 +#!/usr/bin/env python3
  2 +
  3 +'''
  4 +This question generator expects two integer arguments.
  5 +These are the range for the number of coins in each pocket.
  6 +'''
  7 +
  8 +import random
  9 +import sys
  10 +
  11 +a = int(sys.argv[1])
  12 +b = int(sys.argv[2])
  13 +
  14 +x, y = random.sample(range(a, b), k=2)
  15 +r = x + y
  16 +
  17 +pocket1, pocket2 = random.sample(['left pocket', 'right pocket', 'wallet',
  18 + 'safe at home'], k=2)
  19 +
  20 +currency = random.choice(['Euros', 'US dollars', 'British pounds'])
  21 +
  22 +print(f'''---
  23 +type: text
  24 +title: Adding two numbers
  25 +text: |
  26 + Suppose you have {x} {currency} in your {pocket1} and {y} in your
  27 + {pocket2}.
  28 + How many {currency} do you have?
  29 +
  30 + Just answer the number, for example `42`.
  31 +transform: ['trim']
  32 +correct: ['{r}']
  33 +solution: |
  34 + You have a total of {r} {currency}.''')
demo/math/addition/questions.yaml
1 --- 1 ---
2 # --------------------------------------------------------------------------- 2 # ---------------------------------------------------------------------------
3 - type: generator 3 - type: generator
4 - ref: addition-two-digits  
5 - script: addition-two-digits.py  
6 - args: [10, 20]  
7 -  
8 -# ---------------------------------------------------------------------------  
9 -- type: checkbox  
10 - ref: addition-properties  
11 - title: Propriedades da adição  
12 - text: Indique quais as propriedades que a adição satisfaz.  
13 - options:  
14 - # right  
15 - - Existência de elemento neutro, $x+0=x$.  
16 - - Existência de inverso aditivo (simétrico), $x+(-x)=0$.  
17 - - Propriedade associativa, $(x+y)+z = x+(y+z)$.  
18 - - Propriedade comutativa, $x+y=y+x$.  
19 - # wrong  
20 - - Existência de elemento absorvente, $x+1=1$.  
21 - correct: [1, 1, 1, 1, 0]  
22 - solution: |  
23 - A adição não tem elemento absorvente. 4 + ref: addition
  5 + script: addition.py
  6 + args: [2, 20]