I'm trying to create a python program that uses try/except statements. Everything works fine except, I'm still getting a value error, even after defining the except statement.
my code:
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]}
upc_input = int(input('Enter a UPC number: '))
description = input('Enter a, item description: ')
unit_price = float(input('Enter the unit price: '))
quantity = int(input('Enter th quantity: '))
try:
if upc_input in inventory.keys():
print('Inventory Updating')
inventory[upc_input] = [description,unit_price,quantity]
except Excetption as exp:
print('Error occurred!',exp)
try:
if upc_input not in inventory.keys():
print('Adding new inventory')
inventory[upc_input] = [description,unit_price,quantity]
except Excetption as exp:
print('Error occurred!',exp)
print()
print(inventory)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-17-1313cc5c500f> in <module>()
----> 1 upc_input = int(input('Enter a UPC number: '))
2 description = input('Enter a, item description: ')
3 unit_price = float(input('Enter the unit price: '))
4 quantity = int(input('Enter th quantity: '))
5
ValueError: invalid literal for int() with base 10: 'eeeee'