14-May-2026 Exercise 2 (Page 102)

Run Settings
LanguagePython
Language Version
Run Command
def a(x): checknum = x result = 0 level = 1 if checknum < 50000: result = round(checknum * 0.02, 0) else: while (checknum >= 50000 and level <= 5): if level == 1: result = result + round(50000 * 0.02, 0) checknum = checknum - 50000 level = level + 1 elif level == 2: result = result + round(50000 * 0.05, 0) checknum = checknum - 50000 level = level + 1 elif level == 3: result = result + round(50000 * 0.10, 0) checknum = checknum - 50000 level = level + 1 elif level == 4: result = result + round(50000 * 0.15, 0) checknum = checknum - 50000 level = level + 1 elif level == 5: result = result + round(checknum * 0.25, 0) checknum = 0 level = level + 1 else: break if checknum != 0: if level == 1: result = result + round(checknum * 0.02, 0) elif level == 2: result = result + round(checknum * 0.05, 0) elif level == 3: result = result + round(checknum * 0.10, 0) elif level == 4: result = result + round(checknum * 0.15, 0) elif level == 5: result = result + round(checknum * 0.25, 0) return (result) def min_value (a,b): return a if a < b else b i = 0 while i < 5: i = i + 1 user_input = input("Pls input your annual income for Yr 2023:\n") try: number = float(user_input) except ValueError: print("Invalid input. Please try again.") except: print("except error") else: print(f"The result is as follows:") print(f"{'Your income is':<55}{'$':<1}{number:>11.1f}") print(f"{'Your projected accumulated tax:':<55}{'$':<1}{a(number):>11.1f}") standardtax = round(number * 0.16, 0) print(f"{'Your projected standard tax:':<55}{'$':<1}{standardtax:>11.1f}\n") print(f"{'Your payable tax:':<55}{'$':<1}{min_value(standardtax, a(number)):>11.1f}\n") break # Exit loop if conversion is successful
Editor Settings
Theme
Key bindings
Full width
Lines