In: Computer Science
Write a program, called NationalTax, that will simulate calculating a citizen's income tax for the year.
A country uses lettered ID's to identify its citizens. Valid ID's will be either 8 or 9 characters long. All characters entered will be alphabetic characters only (a-z or A-Z).
The following is the python code for the requested scenario. I have checked all the test cases and it is working correctly. I have mentioned the comments in the code for better understanding.
ids = input("Please enter the id")
if(len(ids) > 9):
print("ID invalid")
exit()
tax_year = int(input("Enter the tax year"))
annual_income = float(input("Enter the annual income"))
#creating a positive annual income
annual_income = abs(annual_income)
#convert the income back to string to split it into a list
annual_income = str(annual_income)
#split the annual income into a list of dollars and cents
annual_income_list = annual_income.split(".")
#convert all the id letters to uppercase
ids = ids.upper()
print("The ID is " + ids)
print("The annual income is " + str(annual_income_list[0]) + " dollars and " + str(annual_income_list[1]) + " Cents")
#convert the annual income to float again
annual_income = float(annual_income)
#calculate initial tax
import math
initial_tax = math.log10(int(annual_income)) * 100
print("The initial tax for your annual income is set to " + str(initial_tax))
# #split the id to get each letter as a list and save it in id_list
# id_list = ids.split()
# print(id_list)
#check for government employee i.e. A-G, retired employee etc.
if(ord(ids[0]) >= 65 and ord(ids[0]) <= 71):
initial_tax = initial_tax - (1/10 * initial_tax)
print("being a government employee, the tax has been reduced by 10%. The new tax is " + str(initial_tax))
elif(ord(ids[0]) >= 72 and ord(ids[0]) <= 80):
print("You are a public sector employee, hence no tax deduction")
elif(ord(ids[0]) >= 81 and ord(ids[0]) <= 85):
print("You are unemployed, hence no tax deduction")
else:
initial_tax = initial_tax - (1/4 * initial_tax)
print("being a retired employee, the tax has been reduced by 25%. The new tax is " + str(initial_tax))
#check for 21 years age and increase 100 dollars if ans is yes
if(ord(ids[0]) < ord(ids[len(ids) - 1])):
initial_tax += 100
print("being more than 20 years, the tax has been increased by $100. The new tax is " + str(initial_tax))
else:
print("being less than 21 years, the tax will not be increased. The new tax is " + str(initial_tax))
#check for millionaire
if(ord(ids[5])%7 == 0):
print("Your current tax is " + str(initial_tax))
initial_tax = initial_tax + 15000
print("being a millionaire, the tax will be increased by $15000. The new tax is " + str(initial_tax))
#check for medical professional
if "MED" in ids:
initial_tax = initial_tax - 100
print("being a medical professional, the tax will be reduced by $100. The new tax is " + str(initial_tax))
initial_tax = abs(initial_tax)
#display the final counts
print("For the user ID "+ ids+ " for the tax year "+ str(tax_year) + " and for the annual income of " + str(annual_income) + " the tax you have to pay is " + str(initial_tax))
You may notice that system.exit is used even though the question asked not to but the above program is not inside a function and hence cannot be exited without the use of exit. I did so because I do not know what python version you wanted.
Python 3 will take another syntax and python 2 another. Hence, I left it. All other things are same and works fine.