# Chapter5.py # syntax errors "code is not typed to requirements" programmer / coder # runtime errors "code typed without error BUT program can't start" exit code 1 fail developer "maps out app" # exception errors 'Exception Handlers" runs but during the execution of "operation" fails # Unit Testing or Assertion Errors Backend Developer / Unit Tester ## 4 + 2 * 8 = Assert 48 Credit Card was charged 48 But actual was 20 LOST $28 # 4 + 2 * 8 actual 20 qty + qty * price # (4 + 2) * 8 expected 48 (qty + qty) * price # UI/UX Tester -> workflow # Define a function to calculate a formula # exception handling using try keyword def cartTotalCalc(): try: # try step 1 pass or fail # Step 1 Ask the user for qty desired inputQuantity = int(input("Enter quantity: ")) # int # try step 2 pass or fail # Step 2 Get the price for the product productPrice = 25.52 # Chapter7 come from csv file ## file i/o error handle with except # Step 3 Calculate the line item total lineItemTotal = inputQuantity * productPrice # Step 4 Calculate tax ## tax rate 7% ## (7 / 100) taxrate = 7 # 7% taxcalc = taxrate / 100 subTotal = lineItemTotal + (lineItemTotal * taxcalc) # Step 5 Calculate Shipping """ 0-10 $9.95 if 10.01-25 $12.95 elif over 25 $ 19.95 else """ if (subTotal > 0 and subTotal <= 10): varShippingCost = 9.95 elif (subTotal > 10 and subTotal <= 25): varShippingCost = 12.95 else: varShippingCost = 19.95 # Step 6 Calculate Cart Total varCartTotal = subTotal + varShippingCost print("Cart Information") print("================") print(f"Quantity: {inputQuantity} Price: {productPrice}") print(f"Shipping Cost: {varShippingCost}") print("Cart Total: " + str(varCartTotal)) # Possible Issues except TypeError as err: print("You entered an invalid data type.") print(err) except ZeroDivisionError: print("Can not divide a number by zero.") except Exception as err: print("Something went wrong.") print(err) finally: # pass or fail print("Thank you for using our program.")