I'm using a dictionary in Python and trying to reference one of the data categories however I am getting a keyerror when running the code.
"Restock_Item" will be an eight digit number such as "12345670" which is in the dictionary so by using
stock[restock_item]['STOCK_LEVEL']
it would be referencing the dictionary like this:
stock[12345670]['STOCK_LEVEL']
But when doing this I get the error:
KeyError: 12345670
Here is the code:
restock_item = input("\nPlease enter the gtin code of the product you wish to restock. ")
if restock_item.isdigit() == True:
restock_level = input("How many items would you like to restock? ")
while restock_item.isdigit() == True:
restock_item = int(restock_item)
newStockLevel = int(stock[restock_item]['STOCK_LEVEL']) # This is the line that gets the key error
newStockLevel = newStockLevel + restock_level
stock[restock_item]['STOCK_LEVEL'] = newStockLevel