Dec-12-2022, 05:53 AM
I am new to python and programming, but have enjoyed the semester learning what I have... However we were asked to follow a template and build a point of sale program using a list of products, and a list of prices for those products. User input for the index of the product number, and quantity, then calculate and print a total price including a tax rate. I think I got pretty close, but I am getting an error in the function for the price calculation.
First post, sorry if I don't post it correctly
First post, sorry if I don't post it correctly
# Get app parameters and other hard-coded data: # Assign values to named constants TAX_RATE = 0.10 # Populate arrays with product data: lstProducts = [ 'Iron', 'Home Gym', 'Microwave Oven', 'Cordless Drill', 'Gas Range', 'Washer', 'Stand Mixer', 'Dryer', 'Dishwasher', 'Treadmill', ] lstPrices = [ 24.95, 794.95, 165, 129.95, 495, 399.99, 159.95, 349.95, 595, 1390 ] # Main Program module: def main(): #Call Production selection module: intItemNum = GetProduct() #Get desired quantity from end-user: intQuantity = int(input(f'Desired quantity: ')) #Call Calculation module: fltTotalPrice = CalculatePrice() #Display Result: print (f'Total Price for this purchase is ${fltTotalPrice:.2f}') # Subprogram modules: def GetProduct(): # List product indices and name: # Display list header: print (f'Product List (index - product name -> price):') # Initialize loop counter: i=0 #Use a foreach() construct loop through name and prices arrays for index in range(0, len(lstProducts)): #Display product index and name: print (f"\t{i} - {lstProducts[i]} -> ${lstPrices[i]:.2f}") i +=1 #Get index of desired product from end-user: intProdNum = int(input(f'Index of desired Product: ')) return intProdNum def CalculatePrice(prodIndex,pQuant): #Perfrom Calculations: fltItemPrice = float(lstPrices[intItemNum]) fltBasePrice = float(fltItemPrice*intQuantity) fltNetPrice = float(fltBasePrice*(1+(TAX_RATE))) return main()