I have three parallel arrays product, store and price. The program should ask for the product and store name and then display all the prices against that product and store. I have the following code but it's stopped displaying price once it's found the first value in the sorted price list. Is there any way to search for more than one value from the list? Here is my code.
product = ["Milk","Peanut","Onions","Milk","Onions","Cheese","Potatoes","Cheese"]
store = ["Axep","Dominion","Fortions","Axep","Extra Foods","Loblow","Axep","Loblow"]
price = [2,2,4,10,10,10,17,23]
def search(product,store,price):
enterProduct = input("Enter product: ")
enterStore = input("Enter store: ")
counter = 0
position = 0
found = False
while counter < len(price) and found == False:
if product[counter] == enterProduct and store[counter] == enterStore:
found = True
position = counter
counter = counter + 1
if found == True:
print(f"The price for {product[position]} in {store[position]} are {price[position]}")
def main():
search(product,store,price)
main()
Here is the output:
Enter product: Milk
Enter store: Axep
The price for Milk in Axep are 2
which should be:
The price for Milk in Axep are:
2
10