Jump to content

I need to develop a program that will update stock levels following an order. In the stock file it will need to include the current stock level and target stock level (the number of products required in stock after the product is re-stocked). I need it to calculate which products are out of stock and ask the user (if they don't have the right stock) if they want the remaining stock or just not have any of that item.

 

Could someone help me with this task? Thanks

 

~ Mattonfire.

 

 


 

import math
loop = 1
completeItems = []
completePrice = []
def text(line):
    with open("barcodes.txt","r") as f:
        lines = f.readlines()
        x = lines[line]
        y = lines[line+1]
        print(x)
        ask = int(input("How many would you want: "))
        # Calculating Specific item cost and adding it to the array
        totalPrice = (int(y)*ask)
        completePrice.append(totalPrice)
        totalItem = (str(ask) + "x - £" + str(totalPrice) + " - " + x)
        completeItems.append(totalItem)
def roundup(x):
    return int(math.ceil(x /10)) * 10
while loop == 1:
    again = input("Start - Or add another code? ")
    if again == "y" or again == "Y" or again == "yes" or again == "Yes" or again == "yEs" or again == "yeS" or again == "YeS" or again == "YES":
        strStock = input("Input a barcode: ")
        intStock = 1
        try:
            intStock = int(intStock)
            if (len(strStock) == 7) or (len(strStock) == 8):
                total = int(strStock[0])*3+int(strStock[1])+int(strStock[2])*3+int(strStock[3])+int(strStock[4])*3+int(strStock[5])+int(strStock[6])*3
                rounded = roundup(total)
                digit8 = rounded - total
                if len(strStock) == 8:
                    if int(strStock[7]) == digit8:
                        print("This is a correct 8 Digit Barcode!")
                        if strStock   == "34512340": text(0)
                        elif strStock == "98981236": text(2)
                        elif strStock == "56756777": text(4)
                        elif strStock == "90673412": text(6)
                        else: print("Barcode not listed!")
                    else:   print("Incorrect Barcode! The check digit should be " + str(digit8) + ".")
                else:   print("The check digit is " + str(digit8) + ".")
            else:   print("Please input a correct length barcode.")
        except ValueError:  print ("Thats not an integer!")
    else:
        totalPrice = sum(completePrice)
        print("-- Format --")
        print("Amount of Item | Price | Barcode/Item")
        for elem in completeItems:
            print (elem)
        print("\nThe total price is £" + str(totalPrice) + ".")
        break

 

And this is the barcodes.txt file



34512340 Potato 
5
98981236 Biscuits 
5       
56756777 Strawberries

90673412 Nuggets
1


 

Link to comment
https://linustechtips.com/topic/562369-python-help/
Share on other sites

Link to post
Share on other sites

For anyone who doesn't want to go blind by reading the code:

 

import math
loop = 1
completeItems = []
completePrice = []
def text(line):
    with open("barcodes.txt","r") as f:
        lines = f.readlines()
        x = lines[line]
        y = lines[line+1]
        print(x)
        ask = int(input("How many would you want: "))
        # Calculating Specific item cost and adding it to the array
        totalPrice = (int(y)*ask)
        completePrice.append(totalPrice)
        totalItem = (str(ask) + "x - £" + str(totalPrice) + " - " + x)
        completeItems.append(totalItem)
def roundup(x):
    return int(math.ceil(x /10)) * 10
while loop == 1:
    again = input("Start - Or add another code? ")
    if again == "y" or again == "Y" or again == "yes" or again == "Yes" or again == "yEs" or again == "yeS" or again == "YeS" or again == "YES":
        strStock = input("Input a barcode: ")
        intStock = 1
        try:
            intStock = int(intStock)
            if (len(strStock) == 7) or (len(strStock) == 8):
                total = int(strStock[0])*3+int(strStock[1])+int(strStock[2])*3+int(strStock[3])+int(strStock[4])*3+int(strStock[5])+int(strStock[6])*3
                rounded = roundup(total)
                digit8 = rounded - total
                if len(strStock) == 8:
                    if int(strStock[7]) == digit8:
                        print("This is a correct 8 Digit Barcode!")
                        if strStock   == "34512340": text(0)
                        elif strStock == "98981236": text(2)
                        elif strStock == "56756777": text(4)
                        elif strStock == "90673412": text(6)
                        else: print("Barcode not listed!")
                    else:   print("Incorrect Barcode! The check digit should be " + str(digit8) + ".")
                else:   print("The check digit is " + str(digit8) + ".")
            else:   print("Please input a correct length barcode.")
        except ValueError:  print ("Thats not an integer!")
    else:
        totalPrice = sum(completePrice)
        print("-- Format --")
        print("Amount of Item | Price | Barcode/Item")
        for elem in completeItems:
            print (elem)
        print("\nThe total price is £" + str(totalPrice) + ".")
        break

 

Eien nante naito iikitte shimattar  /  Amarinimo sabishikute setsunai deshou
Dare mo ga hontou wa shinjitai kedo  /  Uragirarere ba fukaku kizu tsuite shimau mono

Link to comment
https://linustechtips.com/topic/562369-python-help/#findComment-7402596
Share on other sites

Link to post
Share on other sites

25 minutes ago, Crowes said:

For anyone who doesn't want to go blind by reading the code:

 


import math
loop = 1
completeItems = []
completePrice = []
def text(line):
    with open("barcodes.txt","r") as f:
        lines = f.readlines()
        x = lines[line]
        y = lines[line+1]
        print(x)
        ask = int(input("How many would you want: "))
        # Calculating Specific item cost and adding it to the array
        totalPrice = (int(y)*ask)
        completePrice.append(totalPrice)
        totalItem = (str(ask) + "x - £" + str(totalPrice) + " - " + x)
        completeItems.append(totalItem)
def roundup(x):
    return int(math.ceil(x /10)) * 10
while loop == 1:
    again = input("Start - Or add another code? ")
    if again == "y" or again == "Y" or again == "yes" or again == "Yes" or again == "yEs" or again == "yeS" or again == "YeS" or again == "YES":
        strStock = input("Input a barcode: ")
        intStock = 1
        try:
            intStock = int(intStock)
            if (len(strStock) == 7) or (len(strStock) == 8):
                total = int(strStock[0])*3+int(strStock[1])+int(strStock[2])*3+int(strStock[3])+int(strStock[4])*3+int(strStock[5])+int(strStock[6])*3
                rounded = roundup(total)
                digit8 = rounded - total
                if len(strStock) == 8:
                    if int(strStock[7]) == digit8:
                        print("This is a correct 8 Digit Barcode!")
                        if strStock   == "34512340": text(0)
                        elif strStock == "98981236": text(2)
                        elif strStock == "56756777": text(4)
                        elif strStock == "90673412": text(6)
                        else: print("Barcode not listed!")
                    else:   print("Incorrect Barcode! The check digit should be " + str(digit8) + ".")
                else:   print("The check digit is " + str(digit8) + ".")
            else:   print("Please input a correct length barcode.")
        except ValueError:  print ("Thats not an integer!")
    else:
        totalPrice = sum(completePrice)
        print("-- Format --")
        print("Amount of Item | Price | Barcode/Item")
        for elem in completeItems:
            print (elem)
        print("\nThe total price is £" + str(totalPrice) + ".")
        break

 

How'd you do that!? xD

Link to comment
https://linustechtips.com/topic/562369-python-help/#findComment-7402735
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×