BranchingConditionalsExamples

Run Settings
LanguagePython
Language Version
Run Command
print("Time to pay your (federal) income tax!") print() taxable_income = int(input("Enter your total taxable income (dollars only): ")) print(taxable_income) # If your taxable income was exactly $11,000, # then your income tax would be $1,100. tier1 = int( 11000 * 0.10 ) # If your taxable income was exactly $44,725, # then your income tax would be $1,100 + # ( 44725 - 11000 ) x 12% tier2 = int( ( 44725 - 11000 ) * 0.12 ) # tier1 + tier2 == $5,147 # print(str(tier1 + tier2)) # Output: 5147 # Python elif is the contraction of else and if. # Read elif as "else if". if taxable_income > 44725 and taxable_income <= 95375: income_tax = tier1 + tier2 + ( ( taxable_income - 44725 ) * 0.22 ) elif taxable_income > 11000 and taxable_income <= 44725: income_tax = tier1 + ( ( taxable_income - 11000 ) * 0.12 ) elif taxable_income <= 11000: income_tax = taxable_income * 0.10 else: print("Error!!") # We want income_tax to be an int (an integer, a whole number, no fractions). income_tax = int( income_tax ) print() print("Your total (federal) income tax is " + str(income_tax))
Editor Settings
Theme
Key bindings
Full width
Lines