237. Python Program to Make a Salary Slip with Net Pay
EasyPhase 1 · Warm-up
You know input(), float() and f-strings with :.2f. That is all you need here.
Overview
A salary slip is a short paper that shows how a worker's pay is worked out. Every company makes one for each worker each month.
Problem Statement
Chen does the pay for a small company. Each worker has a basic pay. On top of it:
- The allowance is 20% of the basic pay. An allowance is extra money, for example for travel.
- The gross pay is the basic pay plus the allowance.
- The tax is 10% of the gross pay.
- The net pay is the gross pay minus the tax. This is the money the worker gets.
Read the basic pay. Print the salary slip as 5 lines, every number with 2 decimal places:
Basic pay: <basic>
Allowance: <allowance>
Gross pay: <gross>
Tax: <tax>
Net pay: <net>
The numbers start in the same column. So after Tax: there are 7 spaces, and after Net pay: there are 3 spaces.
Steps
- Read the basic pay as a decimal number.
- Work out the allowance: 20% of the basic pay.
- Work out the gross pay, then the tax: 10% of the gross pay.
- Work out the net pay: the gross pay minus the tax.
- Print the 5 lines with 2 decimal places.
Examples
Example 1. Input 2000 gives:
Basic pay: 2000.00
Allowance: 400.00
Gross pay: 2400.00
Tax: 240.00
Net pay: 2160.00
Why: 20% of 2000 is 400, so the gross pay is 2400. 10% of 2400 is 240, and 2400 - 240 = 2160.
Example 2. Input 1234 gives:
Basic pay: 1234.00
Allowance: 246.80
Gross pay: 1480.80
Tax: 148.08
Net pay: 1332.72
Why: 1234 × 20 ÷ 100 = 246.8, and 1234 + 246.8 = 1480.8. The tax is 10% of 1480.8, which is 148.08, and 1480.8 - 148.08 = 1332.72.
Input
One number: the basic pay (0 or more). Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
5 lines, as shown above, every number with 2 decimal places. The spaces after Tax: and Net pay: count. The tests try 6 different inputs, also 0.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.