Skip to content

About

A Python program that calculates how much you make in a week, year, and so on. Before and after taxes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

31 Commits

Folders and files

Repository files navigation

Money Calculator

A Python program that calculates how much you make in a week, a month, and a year, before and after taxes.

A real Money Calculator session for $15 an hour, 40 hours a week and 20% tax

A real session: $15 an hour, 40 hours a week, 20% tax.

Requirements

  • Python 3 (no third-party packages are needed)

Running

python3 program2.py

Prompts

Three values are asked for, in this order. Each is entered as a bare number. Spaces around the number are ignored, and scientific notation is accepted (2e1 is read as 20), but a comma used as a thousands separator is not (enter 1000, not 1,000). An underscore between two digits is accepted and ignored (1_000 is read as 1000, and 1_000_000 as 1000000), but two underscores in a row, or one at the start or end, are not.

Order Prompt Example answer Meaning
1 How much do you make per hour before taxes? 15 Gross hourly wage, in dollars — 0 or more
2 How many hours do you work in a week? 40 Hours worked per week — 0 to 168
3 How much percent of your paycheck is taken out for taxes? 20 Tax percentage, as a plain number — 20, not 0.20 or 20% — 0 to 100

An answer that is not a number (such as abc, $15, or 20%) or that falls outside the range shown is refused with a short message, and the same question is asked again. An hourly wage too large to calculate with at all (such as 1e309) is refused the same way, with the message That is too large to calculate. Please try again.; for the hours and the tax percentage, such an answer is simply above the highest value allowed. If the answers are accepted but give figures too large to calculate (such as an hourly wage of 1e307 for a 40-hour week), the message Those answers give figures too large to calculate. Please try again. is shown and all three questions are asked again.

The program then prints three lines — one each for a week, a month, and a year — each giving the pay before taxes and after taxes, and waits on a final Press Enter to exit the program. prompt, so it does not close on its own.

If the input is closed at any prompt instead — by pressing Ctrl-D, or because piped-in answers ran out — the program stops with the message No answer was given, so the program is exiting. and a non-zero exit status. Pressing Ctrl-C at any prompt likewise stops it, with the message The program was interrupted, so it is exiting. and a non-zero exit status.

Example

You will be asked several questions regarding your financial situation.

How much do you make per hour before taxes? (Format: 8.31, 14) $15
How many hours do you work in a week? (Format: 17.56, 40) 40
How much percent of your paycheck is taken out for taxes? (Format: 10, 20, 30, etc) 20

In a week, you will make $600 before taxes and $480 after taxes.

In a month, you will make $2400 before taxes and $1920 after taxes.

In a year, you will make $28800 before taxes and $23040 after taxes.


Press Enter to exit the program.

How the figures are derived

  • Weekly pay before taxes is the hourly wage multiplied by the hours worked per week.
  • Weekly pay after taxes is the weekly pay before taxes, less the given tax percentage.
  • Monthly pay, before or after taxes, is four weeks of the matching weekly figure.
  • Yearly pay is twelve of those months — that is, 48 weeks rather than 52.

Known limitations

  • The printed figures are truncated to whole dollars, so cents are dropped (#5).
  • A year is treated as 48 weeks (#4).
  • Figures of a few billion dollars or more can print a dollar or more away from the exact value, because they are calculated in floating point. For example, 529885.82, 150 and 0 print a year of $3815177903, not $3815177904 (#34).
  • A figure less than half a millionth of a dollar below a whole dollar prints as that whole dollar instead of having its cents dropped, because the rounding that removes floating-point error carries it up. This is rare, and it needs answers with several decimal places between them. For example, 43.56, 60.44 and 42.38 give an exact week after taxes of $1516.99999968, which prints as $1517, not $1516 (#34).

Tests

The arithmetic is covered by pytest tests in tests/. Running the program needs no third-party packages, but running the tests needs pytest installed:

python3 -m pip install pytest
python3 -m pytest

The same tests, a byte-compile of program2.py, and a run of the program with the example answers above are run by GitHub Actions on every push to master and every pull request (.github/workflows/test.yml).

How the screenshot was captured

docs/images/money-calculator.gif was recorded on 2026-10-18 from a real run of python3 program2.py (Python 3.12) with the example answers 15, 40 and 20. The program was started in a pseudo-terminal, the input shown was typed into it by a script, and the recorded terminal output was rendered to an image with pyte and Pillow. Nothing in the output was edited; only the window frame was added.

License

Licensed under the Stephenson Software Non-Commercial License (Stephenson-NC) — non-commercial use only. See LICENSE.

About

A Python program that calculates how much you make in a week, year, and so on. Before and after taxes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages