Objective

Demonstrate your understanding of solving problems that involve using loops and decisions in programs.

Assignment

Write a Python program to use loops and decisions.

Use Python for the following problem helping an IRS agent to calculate income tax based on user income and filing status. We will use loops to process more than one set of input values.

  • Ask for the number of people that we would like to process. Make sure the user inputs a number between 1 and 20 for the number of people. You need to continue asking for a valid number of people until valid data is entered.
  • For each person, in the following order, ask for the filing status (single or married) and income for the person. Assume the user will only enter data in lower case for filing status.
  • If the filing status is entered as anything but single or married, continue asking until a valid filing status is entered.
  • Use the following table to calculate tax:

Income Filing as Single Tax Due
From To
$0 $50,000 10% of income
More than $50,000 $100,000 $2500 + 12% of amount over $50,000
More than $100,000 ... $6000 + 15% of amount over $100,000

Income Filing as married Tax Due
From To
$0 $50,000 5% of income
More than $50,000 $100,000 $2500 + 8% of amount over $50,000
More than $100,000 ... $6000 + 10% of amount over $100,000

  • Calculate tax due.
  • Display filing status, income, and the amount of tax due.
  • Calculate and display the grand total of all income values entered by the user.
  • Calculate and display the grand total of all tax values entered by the user.

Display the following information in a format very close to the following sample run. For example, you need to display the labels as stated, below. Make sure to test for all possible cases to assure your program is functioning properly.

Sample runs

Number of people: -1
ERROR - try again,
Number of people: 30
ERROR - try again,
Number of people: 4

Filing status: single
Income: 60000
Filing status: single
Income: $60000.00
Tax: $3700.00 <): 2500+0.12*(60000 - 50000)

Filing status: joint
Invalid filing status - try again

Filing status: married
Income: 150000
Filing status: married
Income: $150000.00
Tax: $11000.00 <): 6000+0.1*(150000 - 100000)

Filing status: single
Income: 20000
Filing status: single
Income: $20000.00
Tax: $2000.00 <): 0.1*20000

Grand Total of income = $230000.00
Grand Total of tax = $16700.00
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.