Implementing a tax calculator in Python

Source: Internet
Author: User

Introduced

We have developed a tax calculator, after entering the salary, printing the tax payable.

A tax calculation formula:

    1. Taxable income = Salary amount-Various social insurance costs-starting point (3500 yuan)
    2. Taxable amount = Taxable income x tax Rate-Calculator deduction

Each of the social insurance costs we set in this procedure is 0, do not consider.

The tax rate and the Calculator deduction number corresponding table:

Taxable
Income amount Tax rate Calculator Deduction number (yuan)
No more than 1500 yuan 3% 0
Over $1500 to $4500 10% 105
Over $4500 to $9000 20% 555
Over $9000 to $35000 25% 1005
Over $35000 to $55000 30% 2755
Over $55000 to $80000 35% 5505
More than 80000 yuan 45% 13505

For example, if the wage amount is 5000, the taxable income is 1500 (5000-3500) and the taxable amount is 45 yuan (1500 * 3%-0).

The program runs with Python3, and the execution process is as follows

Note that the program executes only one parameter, and the parameter is the wage amount, which needs to be an integer, if the number of arguments is inaccurate or cannot be converted to an integer, you need to print the following line of error message:

Goal

Goals to accomplish:

    1. Where the program is stored/home/shiyanlou/calculator.py
    2. The first parameter that the program executes is the wage amount, which is the way the program executes./calculator.py 3500
    3. The number returned by the program retains two decimal places, and if it is an integer, this form still needs to be preserved xxx.00 .
Cue words
    1. Turning parameters into integers can be used int() , if not correctly converted to integers (for example, int (' ABCD ')), you need to handle the exception and print the above error message.
    2. The output retains two decimal places that can be formatted using the string's format function, for example, format(1.2345, ".2f") a string with two decimal places‘1.23‘
    3. Command-line arguments are obtained by using the SYS module sys.argv , not using input () , which is the sys.argv[0] script name, sys.argv[1] as the first parameter, for example:

Finally, because the next challenge will be to use the code that is now written, either 下载代码 save it locally or submit it to your own Github.

Attention
    1. Try except only need to include code that could have an exception when judging an exception, such as converting an input string to int, without having to include all of the code
    2. The indentation requirement for each line in Python is strict, so be sure not to Mix tab and space, we recommend using spaces to indent, and indent with 4 spaces.
Knowledge points
    • Python3 Program Development
    • Variables and data types
    • Output
    • Command-line arguments
    • Operation
    • String
    • Control structure
    • Exception handling
ImportSYSdefcalculator ():Try: A= Int (sys.argv[1]) Salary= a-3500ifSalary > 80000: Cal_salary= Salary * 0.45-13504elifSalary > 55000: Cal_salary= Salary * 0.35-5505elifSalary > 35000: Cal_salary= Salary * 0.3-2755elifSalary > 9000: Cal_salary= Salary * 0.25-1005elifSalary > 4500: Cal_salary= Salary * 0.2-555elifSalary > 1500: Cal_salary= Salary * 0.1-105Else: Cal_salary= Salary * 0.03Print("{:. 2f}". Format (cal_salary))except:        Print("Parameter Error") calculator ()

Implementing a tax calculator in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.