I'm struggling with some coding. The question is "Create a suitable text file to use with a high-level programming language containing a list of product details, including a GTIN-8 product code, a product description and price. The program should allow a user to enter GTIN-8 codes for a list of products they wish to purchase and the quantity required of each product. The program should search the stock file to produce a list of products with their descriptions, prices, cost for each of the quantity selected and the total cost for all of the products. The program should also identify products not found."
The bit i'm struggling is that i'm not sure how to fetch information from the csv and when the user inputs a GTIN-8 code, for the corresponding product to be printed out.
The bit i'm struggling is that i'm not sure how to fetch information from the csv and when the user inputs a GTIN-8 code, for the corresponding product to be printed out.
order=[] def getData(): data = [] playerData = open('products.csv', mode='r') for line in playerData: line = line.rstrip() data.append(line.split(',')) return data def displayProducts(data): for i in data: print("GTIN: {:12.12} Product: {:12.12} Price {:1.2f}".format(i[0],i[1],float(i[2]))) def main(): product =[] product = getData() print(product) displayProducts(product) main() correct=False while not correct: validate = input("Input your 8 digit GTIN-8 number") if len(validate) == 8 and validate.isdigit(): correct=True Number1=int(validate[0]) Number2=int(validate[1]) Number3=int(validate[2]) Number4=int(validate[3]) Number5=int(validate[4]) Number6=int(validate[5]) Number7=int(validate[6]) Number8=int(validate[7]) GTIN=int(Number1*3+Number2+Number3*3+Number4+Number5*3+Number6+Number7*3+Number8) if GTIN % 10 == 0: print("This GTIN-8 code is valid") quantity=int(input("How many of this product would you like to purchase?")) order.append([validate,quantity]) print(order) else: print("The code you entered is not valid") else: print("You have not input an 8 digit code")