jeudi 29 mars 2018

How to use multiple values for one variable depending on the resulty of an if-else staement?

In the code sample below I want to make it so that deductions would equal one of the 4 values depending on the input the user enters (look at the if-else statement). Is this possible?

deductions1 = 0.12 + 0.04 + 0.01 + 0.06
deductions2 = 0.20 + 0.07 + 0.03 + 0.06
deductions3 = 0.30 + 0.09 + 0.05 + 0.06
deductions4 = 0.38 + 0.11 + 0.07 + 0.06
deductions = monthly_salary = hours_worked * hourly_pay

if monthly_salary < 4000:
    deduction_rate = deductions1
elif monthly_salary >= 4000 and monthly_salary < 8000:
    deduction_rate = deductions2
elif monthly_salary >= 8000 and monthly_salary < 16000:
    deduction_rate = deductions3
else:
    deductions = deductions4

net_salary = monthly_salary - (deductions * monthly_salary)

Aucun commentaire:

Enregistrer un commentaire