#!/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))