def driver_check(age, road_test): '''can drive if you've passed the road test and are at least 16, if not passed road test, can still get a permit if at least 15''' if road_test: print("yes, can drive") elif age >= 15: print("learner's permit only") else: print("no, can't drive") def water_type(temp): '''return 'solid', 'liquid', or 'gas' depending on water temp. colder than 32 is ice, warmer than 212 is gas''' if temp < 32: return 'solid' elif temp < 212: return 'liquid' else: return 'gas' def letter_grade(score): '''return the letter grade corresponding to the given score''' if score >= 90: return 'A' elif score >= 80: return 'B' elif score >= 70: return 'C' elif score >= 60: return 'D' else: return 'F' def effective_tax(income): '''return effective tax rate given the following marginal tax rates: 0% up to \$10k 10% up to \$30k 25% up to \$60k 35% up to \$100k 50% over \$100k''' taxes = 0 remaining = income if remaining > 100000: # we have income to tax at 50% margin = remaining - 100000 taxes += margin * 0.5 remaining = 100000 if remaining > 60000: # we have income to tax at 35% margin = remaining - 60000 taxes += margin * 0.35 remaining = 60000 if remaining > 30000: # income to tax at 25% margin = remaining - 30000 taxes += margin * 0.25 remaining = 30000 if remaining > 10000: # income to tax at 10% margin = remaining - 10000 taxes += margin * 0.1 # ignore the last 10000 (no tax) # compute the effective tax rate using total tax return taxes / income