In Pythonwrite a function that takes 0 parameters and asks t

In, Python,write a function that takes 0 parameters and asks the user for their income over the past year. The function will then calculates their taxes according to the following (hypothetical!) scenario:  For an income of under $100,000, the tax rate is 30%. For an income of $100,000 or above, but under $200,000, the tax rate if 35%. For an income $200,000 or above but below $500,000, the tax rate is 40%. For an income $500,000 or above, the tax rate is 45%. You do not need to worry about the number of decimal places. When you read in the income, use casting to convert the string to a float. That is, do not use the \'eval()\' function.

calc taxes What is your income? 50000 Your declared income is 50000.0 Your tax rate is 30.0 You owe 15000.0 calc taxes What is your income? 150000 Your declared income is 150000.0 Your tax rate is 35.0 You owe: 52500.0 calc taxes What is your income 200000 Your declared income is 200000.0 Your tax rate is 40.0 You owe 80000.0 calc taxes What is your income? 2000000 Your declared income is 2000000.0 Your tax rate is 45.0 You owe 900000.0

Solution

Please find the required program and output below: Please find the comments against each line for the description:

def calc_taxes():   # function to calculate calc_taxes
   income = input(\"What is your income?\")   #read income
   incomeFlt = float(income)   #convert income from string to float format
   print (\"Your declared income is: \",incomeFlt)   #print the income in float
   tax = 0       #initialize tax rate
   if(incomeFlt < 100000):   #if income is less than 100000; the tax = 30
       tax = 30
   elif(incomeFlt < 200000):       #if income is less than 200000; the tax = 35
       tax = 35
   elif(incomeFlt < 500000):       #if income is less than 3500000; the tax = 40
       tax = 40
   else:   #else for all other case
       tax = 45
      
   print (\"Your tax rate is: \",tax)   #print the tax rate
   print (\"You owe: \",(tax * incomeFlt / 100))   #print the owe value
      
  
calc_taxes()   #call the function

-------------------------------------------

OUTPUT:

In, Python,write a function that takes 0 parameters and asks the user for their income over the past year. The function will then calculates their taxes accordi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site