A maths test
Project description
Matt
Matt is a free software (licensed under the GNU GPL v3 (or later)) maths test program. "Matt" (or "MATT") is a recursive acronym for "MATT Arithmetic Training Test".
Installation
Matt depends on:
There are 2 methods of installation: via poetry and via pip:
Installation via poetry
Poetry should handle the installation of dependencies. To install, first clone the git repository, then run:
poetry install
Installation via pip
Pip should handle the installation of dependencies. To install, run:
python3 -m pip install matt
Usage
Run python3 -m matt -h for help.
Matt accepts the following arguments:
-
--difficultyor-dto set the difficulty (in the format "<namespace>:<number>"). Thedefaultnamespace is reserved for the default difficulties. If unspecified the default isdefault:1. -
--operationsor-oto set the available operations. Operations are separated by commas, the available operations are:+: Addition-: Subtraction*: Multiplication/: Division
One can also use custom operators defined in the configuration.
Example:
-o +,-to enable only addition and subtraction. -
--minimumor-mto set the minumum, default (if not specified in difficulty): 0. -
--maximumor-Mto set the maximum, default (if not specified in difficulty): 10. -
--question-amountor-qto set the amount of questions, the default is 10.
NOTE: The maximum must be more than the minimum.
Config
Matt has a configuration file, it is written in Python,
and located at $XDG_CONFIG_HOME/matt/config.py.
By default $XDG_CONFIG_HOME is set to ~/.config,
so if you have not set it then it is probably ~/.config/matt/config.py.
The configuration can define custom difficulties and custom operations.
Matt's builtin difficulties/operations are defined in matt/defaults.py,
and they are defined in the same way as custom ones so you can look there for further examples
and details on Matt's defaults.
Defining custom difficulties
The configuration can provide a difficulty function that accepts 2 parameters:
-
namespace(str): The namespace of the difficulty. -
number(int): The number of the difficulty.
The difficulty function must return a dict or None (although if it simply returns None then it is useless).
The dict can have the following keys:
-
minimum(int): the minimum number -
maximum(int): the maximum number -
operations(a list of strs (typing.List[str])): a list of allowed operations
A simple example is:
from typing import Union
def difficulty(namespace: str, number: int) -> Union[dict, None]:
if namespace == "manual":
if number == 1:
return {
"operations": ["+", "-"],
"maximum": 20,
"minimum": 10
}
return None
It is also possible to create a dynamic maximum, like the following example, which creates a difficulty called "automatic", whose maximum is the number * 10:
from typing import Union
def difficulty(namespace: str, number: int) -> Union[dict, None]:
if namespace == "automatic":
return {
"operations": ["+", "-", "*", "/"],
"maximum": number * 10
}
return None
Defining custom operations
The configuration can provide a operations dict to define custom operations.
The keys are the names of the operations,
and the values are dicts which can contain the following keys:
format(function): a function which takes 2 numbers and returns a str. The str is usually a string which contains both values and the operation, it is used to ask the user about the answer. Unlessformat_full_overrideorformat_colour_overrideare set to True, it is sent to the user prepended withWhat is, and appended with?. an example of a function used forformatis (this example would be for the+operation):
lambda n1, n2: f"{n1} + {n2}"
If this is not set then the default is <n1> <operation> <n2>.
function(function): a function which takes 2 numbers, and returns the correct answer for those 2 numbers. This must be defined. Example (for a strange operation that is the result of addition - 1):
lambda n1, n2: n1 + n2 - 1
-
format_full_override(bool): if this is True thenWhat is/?are not added to the string. -
format_colour_override(bool): if this is True then the string is not coloured.
An example which defines an operation called ! that is the result of addition -1,
and an operation called ++ that is the same as addition but just gives the user the answer:
from operator import add
operations: dict = {
"!": {
"function": lambda n1, n2: n1 + n2 - 1
},
"++": {
"function": add,
"format": lambda n1, n2: f"Type {n1 + n2}! ",
"format_full_override": True
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matt-0.2.0.tar.gz.
File metadata
- Download URL: matt-0.2.0.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.6 Linux/5.8.13-gnu
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3fc9886d92c32a10dec0702027fa9a7aa0bda6879568c476dcde16bf49521f5
|
|
| MD5 |
3b18140907e6eccfae84d7f50a3eb492
|
|
| BLAKE2b-256 |
d751853148897581f70d84c1fcfd8532a555e84954243d9af55baff66bfff934
|
File details
Details for the file matt-0.2.0-py3-none-any.whl.
File metadata
- Download URL: matt-0.2.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.6 Linux/5.8.13-gnu
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff9dae5cf746c642005659c5659b859455eacdbebf6210a1f398bfb529d376bf
|
|
| MD5 |
5cc5e6ec26bf4a5c1459d9b6415b9b50
|
|
| BLAKE2b-256 |
74b56af5a7e77411560b0cb55aa3a1c671e7f2c99ba68437b596e661c9daf5ae
|