Python Forum
point of sale code problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
point of sale code problem
#1
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

# 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()
Reply


Messages In This Thread
point of sale code problem - by dethnode - Dec-12-2022, 05:53 AM
RE: point of sale code problem - by DPaul - Dec-12-2022, 10:12 AM
RE: point of sale code problem - by popejose - Dec-12-2022, 12:48 PM
RE: point of sale code problem - by Larz60+ - Dec-13-2022, 01:55 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020