Python Forum
Simple problem. looking for an efficient way
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple problem. looking for an efficient way
#1
I am absolutely new to python without any prior programming knowledge. my question is there an easy way to combine the categories given below in an efficient way. instead of writing the same thing over and over again can it be done more efficiently?

#Income Tax Calculation
print ("Category of the Tax Payers")
print ("---------------------------")
print ("1: Single")
print ("2: Married Filing Jointly")
print ("3: Married Filing Seperately")
print ("4: Head of Household")
category = eval(input("Please specifiy your category. e.g., 1,2,3,4: "))
income = eval(input("Please enter your income amount. e.g., 90000: "))
if category == 1:
    a = 8350
    b = 33950
    c = 82250
    d = 171550
    e = 372950
    if income <= a:
        tax_amount = income * 0.1
    elif income <= b:
        tax_amount = a * 0.1 + (income-a) * 0.15
    elif income <= c:
        tax_amount = a * 0.1 + b * 0.15 + (income-b) * 0.25
    elif income <= d:
        tax_amount = a * 0.1 + b * 0.15 + c * 0.25 + (income-c) * 0.28
    elif income <= e:
        tax_amount = a*0.1 + b*0.15 + c*0.25+ d*0.28+(income-d)*0.3
    else:
        tax_amount = a*0.1+b*0.15+c*0.25+d*0.28+e*0.3+(income-e)*0.35
    print ("Your tax amount is: ",tax_amount)
elif category == 2:
    a = 16700
    b = 33950
    c = 68525
    d = 104425
    e = 186475
    if income <= a:
        tax_amount = income * 0.1
    elif income <= b:
        tax_amount = a * 0.1 + (income-a) * 0.15
    elif income <= c:
        tax_amount = a * 0.1 + b * 0.15 + (income-b) * 0.25
    elif income <= d:
        tax_amount = a * 0.1 + b * 0.15 + c * 0.25 + (income-c) * 0.28
    elif income <= e:
        tax_amount = a*0.1 + b*0.15 + c*0.25+ d*0.28+(income-d)*0.3
    else:
        tax_amount = a*0.1+b*0.15+c*0.25+d*0.28+e*0.3+(income-e)*0.35
    print ("Your tax amount is: ",tax_amount)
elif category == 3:
    a = 8350
    b = 33950
    c = 68525
    d = 104425
    e = 186475
    if income <= a:
        tax_amount = income * 0.1
    elif income <= b:
        tax_amount = a * 0.1 + (income-a) * 0.15
    elif income <= c:
        tax_amount = a * 0.1 + b * 0.15 + (income-b) * 0.25
    elif income <= d:
        tax_amount = a * 0.1 + b * 0.15 + c * 0.25 + (income-c) * 0.28
    elif income <= e:
        tax_amount = a*0.1 + b*0.15 + c*0.25+ d*0.28+(income-d)*0.3
    else:
        tax_amount = a*0.1+b*0.15+c*0.25+d*0.28+e*0.3+(income-e)*0.35
    print ("Your tax amount is: ",tax_amount)
elif category == 4:
    a = 11950
    b = 45500
    c = 117450
    d = 190200
    e = 372950
    if income <= a:
        tax_amount = income * 0.1
    elif income <= b:
        tax_amount = a * 0.1 + (income-a) * 0.15
    elif income <= c:
        tax_amount = a * 0.1 + b * 0.15 + (income-b) * 0.25
    elif income <= d:
        tax_amount = a * 0.1 + b * 0.15 + c * 0.25 + (income-c) * 0.28
    elif income <= e:
        tax_amount = a*0.1 + b*0.15 + c*0.25+ d*0.28+(income-d)*0.3
    else:
        tax_amount = a*0.1+b*0.15+c*0.25+d*0.28+e*0.3+(income-e)*0.35
    print ("Your tax amount is: ",tax_amount)
else:
    print ("Please enter the valid category")
Reply


Messages In This Thread
Simple problem. looking for an efficient way - by silverchicken24 - Oct-13-2019, 04:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A more efficient code titanif 2 555 Oct-17-2023, 02:07 PM
Last Post: deanhystad
  Cleaning my code to make it more efficient BSDevo 13 1,597 Sep-27-2023, 10:39 PM
Last Post: BSDevo
  A simple problem, how best to solve it? SuchUmami 2 785 Sep-01-2023, 05:36 AM
Last Post: Pedroski55
  Making a function more efficient CatorCanulis 9 2,032 Oct-06-2022, 07:47 AM
Last Post: DPaul
  How to solve this simple problem? Check if cvs first element is the same in each row? thesquid 2 1,328 Jun-14-2022, 08:35 PM
Last Post: thesquid
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,881 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
Big Grin question about simple algorithm to my problem jamie_01 1 1,755 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  I there a more efficient way of printing ? Capitaine_Flam 7 3,655 Dec-01-2020, 10:37 AM
Last Post: buran
  A more efficient way of comparing two images in a python vukan 0 2,064 Mar-17-2020, 11:39 AM
Last Post: vukan
  simple login problem MMOToaster 2 2,465 Feb-25-2020, 09:28 AM
Last Post: MMOToaster

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020