Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I don't know what is wrong with my condition statements

income = float(input("your income: "))
if income <= 100000:
    initialIncome = income * .5 
elif income in range (100001,250000):
    initialIncome = income * .10
elif income in range (250001,500000):
    initialIncome = income * .15
elif income >= 500001:
    initialIncome = income * .20

status = input("status (s,m,w,d) ")
if status == "S":
    S = 10000
elif status == "M":
    S = 20000
elif status == "W":
    S = 10000
elif status == "D":
    S = 30000

dependents = float(input("dependents num: "))
if dependents >= 5:
    dependentsPrice = 50000
if dependents <= 5:
    dependentsPrice = 10000 * dependents


totalTax = initialIncome - (status + dependents)

print(totalTax)

#Its not working #this is what I am trying to do

finding out the tax of a person and subtract some based on their status and dependents

my expected output is the user will enter its income then will multiply how much tax

#will be deducted and will also deduct some based on their status and how many #dependents

#they have.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

*#Income: 500000

#Status: Married

#Dependents: 3

#Tax = 25000****

>Solution :

Code:

  • You are using status in totalTax instead of S.
  • You must add .upper() to convert all the input strings to upper case as you have used uppercase in if statements.
income = float(input("your income: "))
if income <= 100000:
    initialIncome = income * .5 
elif income in range (100001,250000):
    initialIncome = income * .10
elif income in range (250001,500001):
    initialIncome = income * .15
elif income >= 500001:
    initialIncome = income * .20

# Here you must add upper to convert all the strings to upper case
status = input("status (s,m,w,d) ").upper()
if status == "S":
    S = 10000
elif status == "M":
    S = 20000
elif status == "W":
    S = 10000
elif status == "D":
    S = 30000

dependents = float(input("dependents num: "))
if dependents >= 5:
    dependentsPrice = 50000 *dependents
if dependents <= 5:
    dependentsPrice = 10000 * dependents

# Here status is string. I suppose you are trying to use S.
#here use dependsPrice
totalTax = initialIncome - (S + dependentsPrice) 

print(totalTax)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading