# this file available at: https://arachnoid.com/files/python01/ import math from typing import List def beginner_error_00(): print(f'{example}: Loop numeric float test error.') n = 1 while n > -1: print(f'n = {n:18.15f} or {n:22.15e}') # test for zero if n == 0.0: break else: n -= .1 def beginner_error_01_append(mylist :List[str] = []): # a function default value is only applied # once, when the function is defined, not # each time the function is called. mylist.append("appended value") print(mylist) def beginner_error_01(): for _ in range(3): beginner_error_01_append() def beginner_error_02(): x = math.log(0) print(f'x = {x}') print('Function continues from here.') def beginner_error_03(): try: x = math.log(0) print(f'x = {x}') except: print('Something went wrong!') y = 1/0 print(f'x = {y}') print('Function continues from here.') def beginner_error_04(): try: x = math.log(0) print(f'x = {x}') except Exception as err: print(f'Error: {err}') try: y = 1/0 print(f'x = {y}') except Exception as err: print(f'Error: {err}') print('Function continues from here.') errors = ( beginner_error_00, beginner_error_01, beginner_error_02, beginner_error_03, beginner_error_04, ) example = 4 errors[example]()