I'm making a simple grocery buying program that uses 2 fixed lists and 2 that can have elements added by the user.
product_list = ['apple', 'orange', 'watermelon', 'banana', 'coconut']
price_list = [ 5.32 , 6.45 , 2.37 , 5.32, 6.45 ]
bought_product_list = [ ]
bought_price_list = [ ]
while True:
product_code = input('Enter the product code: ')
if product_code not in product_list:
print('Invalid product code! Try again!')
if product_code in product_list:
quantity = int(input('Enter the quantity:'))
for q in range(quantity):
bought_product_list.append(product_code)
I can add the product_code to the bought_price_list, but I need a way to import the correct price associated with the product_code from the other lists.
Let's say the user types apple with the quantity 2 and watermelon with the quantity 3, the output should be:
bought_product_list = [ 'apple', 'apple', 'watermelon' , 'watermelon' , 'watermelon' ]
bought_price_list = [ 5.32 , 5.32 , 2.37 , 2.37 , 2.37 ]
Can someone help me with this question?