matematik_islemleri
A small Python library for doing math operations with short, Turkish-named functions.
matematik_islemleri is a small Python library for doing basic math with short, Turkish-named methods. It gathers operations ranging from addition and subtraction to factorials, permutations, logarithms and trigonometric functions into a single class. It also includes two methods for calculating prices with and without tax. I wrote it in November 2023.
Purpose
For students who are new to Python and not yet used to English terms, names like math.factorial or math.comb can look meaningless at first. I made this library so the same operations can be done with Turkish names such as faktoriyel, kombinasyon and karekok_alma, making it clear what the code does on first reading.
How it works
The library has a single class named m. The class is created with the number to work on, for example m(20), and then its methods are called. Writing m(20).toplama(10) returns 30. The methods that work with two numbers are addition, subtraction, multiplication, division, exponentiation, modulo, permutation, combination and logarithm. The ones that work with a single number are factorial, square root, and a trigonometric method that returns the sine, cosine and tangent of the given angle together.
Most methods take an optional parameter called detay. When it is set to True, the result is returned with the name of the operation in front of it, giving an explained output such as "Toplama: 30" on screen. When an invalid value is given, the program does not stop; a Turkish error message is returned instead. Division by zero is checked separately as well.
The tax methods were added for commercial calculations. vergi_dahil_fiyat starts from a tax-inclusive price and a tax rate and works out the price before tax and the tax amount. vergi_haric_fiyat adds tax to a pre-tax price and finds the total. In both methods, the number of decimal places to round to can be passed as a parameter.
Key features
- Every operation is done with a Turkish-named method.
- On bad input the program does not crash; it returns a clear message in Turkish.
- Optional explained output makes the results easier to read on screen.
- Ready-made methods are included for calculating rate-based taxes such as VAT.
Technical stack
The code is a single Python file and uses only the math module from the standard library. Because permutations and combinations rely on math.perm and math.comb, Python 3.8 or later is required. Inputs are converted to integers before the calculation, so decimal numbers are cut down to whole numbers first. Results are returned as text.
Use cases
- It can be used as an example when teaching classes, objects and methods with Turkish names in Python lessons.
- It can be a starting point for students writing simple calculator programs.
- It offers a small example of how price and tax calculations are done.
- Category
- Python libraries
- Year
- 2023
Technologies
- Python
- Education
Links
- GitHub https://github.com/muslu/matematik_islemleri