Quick actions

cmd+k|ctrl+k

Navigation

Languages

21-May-2026 Lesson 10 (Additional 3)(P.94)-REVISED

Snippet info

Language

Python

Visibility

public

Author

michaelluiwaihung

Created

2026-05-27T06:21:09.957814Z

Updated

2026-05-27T06:41:27.010423Z

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("-"*70)
        print(f"{'Your income is':<55}{'$':<1}{number:>13,.1f}")
        print(f"{'Your projected accumulated tax:':<55}{'$':<1}{a(number):>13,.1f}")
        standardtax = round(number * 0.16, 0)
        print(f"{'Your projected standard tax:':<55}{'$':<1}{standardtax:>13,.1f}\n")
        print(f"{'Your payable tax:':<55}{'$':<1}{min_value(standardtax, a(number)):>13,.1f}\n")
        print("-"*70)
        break # Exit loop if conversion is successful
INFO