1
0
Fork
You've already forked mathfun
0
An educational package for utilites to teach basic math on the console.
Python 100%
2025年11月16日 18:52:48 +01:00
src/mathfun Avoid TypeError in case of no input 2020年11月08日 11:14:21 +01:00
tests Add quiz 2020年11月08日 10:58:23 +01:00
.gitignore Modernize packaging with uv 2025年11月16日 18:52:48 +01:00
LICENSE First commit 2020年11月02日 20:56:51 +01:00
pylock.toml Modernize packaging with uv 2025年11月16日 18:52:48 +01:00
pyproject.toml Modernize packaging with uv 2025年11月16日 18:52:48 +01:00
README.md Readme rm syntax higlighting for quiz example 2020年11月08日 10:59:33 +01:00

Math(ematical) Fun(ctions)

An educational package with utilities to teach basic math on the console.

Installation

Setup a python virtual environment and then,

pip install https://codeberg.org/ashwinvis/mathfun/archive/main.tar.gz

Features

Multiplication tables

Generate multiplication tables of any integer and show how it is nothing but reduced addition. The table is displayed with colours using the rich library.

$ python -m mathfun.tables 9
┏━━━━━━━━━━━┳━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ _ times 9= ┃ in words ┃ is same as ┃
┡━━━━━━━━━━━╇━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 090 │ zero │ │
│ 199 │ nine │ 9 │
│ 2918 │ eighteen │ 9 + 9 │
│ 3927 │ twenty-seven │ 9 + 9 + 9 │
│ 4936 │ thirty-six │ 9 + 9 + 9 + 9 │
│ 5945 │ forty-five │ 9 + 9 + 9 + 9 + 9 │
│ 6954 │ fifty-four │ 9 + 9 + 9 + 9 + 9 + 9 │
│ 7963 │ sixty-three │ 9 + 9 + 9 + 9 + 9 + 9 + 9 │
│ 8972 │ seventy-two │ 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 │
│ 9981 │ eighty-one │ 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 │
│ 10990 │ ninety │ 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 + 9 │
└───────────┴────┴──────────────┴───────────────────────────────────────┘

Numbers to text

Convert numbers to their text equivalent. Works for any integer until order of trillions. This example code converts some random numbers in the range.

$ python -m mathfun.text
 79503262279 = seventy-nine billion, five hundred and three million, two hundred and sixty-two thousand, two hundred and seventy-nine
 18 = eighteen
 716859 = seven hundred and sixteen thousand, eight hundred and fifty-nine
 5 = five
 3755909 = three million, seven hundred and fifty-five thousand, nine hundred and nine
 8103390315 = eight billion, one hundred and three million, three hundred and ninety thousand, three hundred and fifteen
 963749 = nine hundred and sixty-three thousand, seven hundred and forty-nine
 65171203 = sixty-five million, one hundred and seventy-one thousand, two hundred and three
 9266 = nine thousand, two hundred and sixty-six
 63531 = sixty-three thousand, five hundred and thirty-one

Quiz

Ask interactive arithmetic questions with encouraging responses.

$ python -m mathfun.quiz
╔═══════════════════════════════════════════════════════════════════════════════════════════╗
║ What is 9 - 5? ║
╚═══════════════════════════════════════════════════════════════════════════════════════════╝
(f) 1 (g) 3 (h) 4 
Answer? h
That's correct 😎
╔═══════════════════════════════════════════════════════════════════════════════════════════╗
║ What is 2 + 1? ║
╚═══════════════════════════════════════════════════════════════════════════════════════════╝
(f) 3 (g) 3 (h) 4 
Answer? 3
Good job 🤩
╔═══════════════════════════════════════════════════════════════════════════════════════════╗
║ What is 3 - 3? ║
╚═══════════════════════════════════════════════════════════════════════════════════════════╝
(f) 0 (g) 0 (h) 0 
Answer? a
Expected a number or an alphabet: f, g, h. Try again.
Answer? g
Well done 😄
╔═══════════════════════════════════════════════════════════════════════════════════════════╗
║ What is 9 + 0? ║
╚═══════════════════════════════════════════════════════════════════════════════════════════╝
(f) 3 (g) 4 (h) 9 
Answer? 10
Oopsie daisy !?
You chose 10. It should have been 9
╔═══════════════════════════════════════════════════════════════════════════════════════════╗
║ What is 10 + 7? ║
╚═══════════════════════════════════════════════════════════════════════════════════════════╝
(f) 16 (g) 17 (h) 15 
Answer? g
Yay 🥳

Wishlist

  • Property testing and example based testing.
  • Generalize code, if possible

Contributing

Clone the repository and prepare for development:

cd mathfun/
python -m venv venv
source venv/bin/activate
pip install flit
flit install --symlink --extras tests

Start hacking. Patches and pull-requests welcome. Make sure tests pass; at least a handful of passes (we use property-based testing using hypothesis):

pytest --count 42