multiplication-table.py
812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import json
import random
x, y = random.sample(range(2,10), k=2)
r = x * y
yy = '+'.join([str(y)]*x)
xx = '+'.join([str(x)]*y)
xbullets = x * '*' # ⏺
xxbullets = '\n'.join(y * [xbullets])
ybullets = y * '*'
yybullets = '\n'.join(x * [ybullets])
solution = f'''
Multiplying is essentially repeating the addition multiple times.
We can do it in two ways:
$$
{x}\\times {y} = {yy} = {r}
$$
or
$$
{y}\\times {x} = {xx} = {r}.
$$
Multiplication can also be seen as the number of dots organised in rectangular
shape:
{xxbullets}
{yybullets}
'''
question = {
'type': 'text',
'title': 'Multiplication (table)',
'text': f'What is the result of ${x}\\times {y}$?',
'transform': ['trim'],
'correct': [f'{r}'],
'solution': solution,
}
print(json.dumps(question))