I need this written in python, using the def main( ) function Compute tax based
ID: 3789396 • Letter: I
Question
I need this written in python, using the def main( ) function
Compute tax based on the original U.S. income tax of 1913. The tax was 1 percent on the first $50,000. 2 percent on the amount over $50,000 up to $75,000. 3 percent on the amount over $75,000 up to $100,000. 4 percent on the amount over $100,000 up to $250,000. 5 percent on the amount over $250.000 up to $500,000. 6 percent on the amount over $500,000. There was no separate schedule for single or married taxpayers. Write a program TaxCalculator.py that asks the user for the income and computes the income tax according to this schedule. Display the income and corresponding taxExplanation / Answer
#!/bin/python
import sys
def tax_calculate(salary) :
tax =0.0 #declare tax as float value
####Let's define the different conditions for calculating taxes using if elif#####
if salary<=50000:
tax = 0.01 * salary
elif salary<=75000 and salary > 50000:
tax = 0.02 * salary
elif salary<=100000 and salary > 75000:
tax = 0.03 * salary
elif salary<=250000 and salary > 100000:
tax = 0.04 * salary
elif salary<=500000 and salary > 250000:
tax = 0.05 * salary
elif salary>500000:
tax = 0.06 * salary
else:
print "Wrong input"
print "Tax to be paid: $%.2f"%tax ## %.2 helps print the calculated value of tax upto two decimal places
if __name__ == "__main__":
while True: ##To accept only integer income from user
try:
salary = int(raw_input("Please enter your income: "))#inputs the income from user and converts it to int
print " Your income: $%.2f " %salary ##%.2 helps display the income upto two decimal places
except: ##input other than integer is discarded and user is asked to enter input again
print (" WRONG INPUT ")
else:
break
tax_calculate(salary) ##Call the tax_calculation method which calculates and displays the tax to be paid
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.