[Solved] How to catch specific index error in Python and attach new value for this? [closed]

There must be a more elegant answer to that but you can do : def extract_values(values): try: first = values[0] except IndexError: first = None try: second = values[1] except IndexError: second = None try: third = values[3] except IndexError: third = None return first, second, third 2 solved How to catch specific index error … Read more

[Solved] Try / Except Statements in python [closed]

inventory = {847502: [‘APPLES 1LB’, 1.99, 50], 847283: [‘OLIVE OIL’, 10.99, 100], 839529: [‘TOMATOS 1LB’, 1.29, 25], 483946: [‘MILK 1/2G’, 3.45, 35], 493402: [‘FLOUR 5LB’, 2.99, 40], 485034: [‘BELL PEPPERS 1LB’, 1.35, 28], 828391: [‘WHITE TUNA’, 1.69, 100], 449023: [‘CHEESE 1/2LB’, 4.99, 15]} while True: try: upc_input = int(input(‘Enter a UPC number: ‘)) break except … Read more