the question which I am working on is this: A program for a supermarket, that checks whether a product is available or not, and then bills the product. If the product ID is present in the list of product IDs, you can add the product to the bill. Once the product is sold, you will decrease the number of products in stock.
product = ["apple", "pear", "banana", "orange", "guava"]
productID = ["a", "p", "b", "o", "g"]
productLeft = [3, 3, 3, 3, 3]
buy = str(input("enter product ID"))
if any(buy in s for s in productID):
num = int(productID.index(buy))
left = productID[num]
if left != 0 :
left = left-1
productLeft[num] = left
I'm getting this error message:
left = left-1
TypeError: unsupported operand type(s) for -: 'str' and 'int'
and if do this:
left = int(productID[num])
then I get this error message:
left = int(productID[num])
ValueError: invalid literal for int() with base 10: 'a'
Please help what correction should I make in my current code and how I should proceed
dictthat maps a product ID to its name and quantity, perhaps something like{"a": ["apple", 3], "p": ["pear", 3]}. Then you can get the name or quantity withproducts["a"][0]orproducts["a"][1], respectively.