so I am trying to learn python and have a csv file like this
1 product_id product_name price
2 1001 cake 15
3 1002 sprite 30
4 1003 coffee 50
5 1004 ice cream 30
6 1005 banana 10
my program is
import csv
productid=input("Enter the product ID: ")
quantity=int(input("Enter the quantity: "))
csv_file=csv.reader(open("shoppinglist.csv", "r"),delimiter=",")
for row in csv_file:
if productid==row[0]:
product_id=row[0]
product_name=row[1]
product_price=row[2]
print("\nProduct ID: {}".format(row[0]))
print("Product Name: {}".format(row[1]))
print("Product Price: {}".format(row[2]))
total=quantity*(int(product_price))
print("\nThe Total Amount Payable is: {}".format(total))
I can enter one productid at a time and get the output but i am looking for a way so that i can enter multiple productid's ad they get searched in the csv file and then the total is calculated and all the product details output.
PS: I have tried to explain my problem as best as i can but if i have made any mistake please be kind to point it out to me
my output is
Enter the product ID: 1001 Enter the quantity: 5
Product ID: 1001 Product Name: cake Product Price: 15
The Total Amount Payable is: 75
i just do not want to print the product but to search for its id in the csv file and if it exits ask the user to input the quantity for every productid entered and then print the details of the products along with the total amount.
