Adding to a shopping basket, and taking the equivalent from the stock
<p>on python 3</p>

<p>Hi, I have a stock of products (as a dictionary. where each key is the identification number and each value is a dictionary of information). The program takes in a identification number (product wanted) and the desired amount.
Then the code is supposed to add the product info into a empty basket, edit the number in stock to the original minus the inputted amount. and edit the amount in the basket to the amount desired.</p>

<p>however the code keeps making the amount of the product in the stock output zero. And the amount of the product in the basket to output zero too.</p>

<p>via the print command I think I have located the problem. somewhere in the if statement below.</p>

<p>but it looks so simple I don't know where I'm going wrong !</p>

<p>Thanks very much in advance. the stock and a 'pretty' print function are at the top of the code, to help you visualise the situation</p>

<pre><code>            stock = {
                '10005' : {
                        'name' : 'Conference Pears Loose',
                        'price' : 2.00,
                        'unit' : 'kg', 
                        'promotion' : None,
                        'group' : None,
                        'amount' : 1.550
                 },
                 '10013' : {
                        'name' : 'Emmental Slices 250G',
                        'price' : 1.75,
                        'unit' : 'pieces', 
                        'promotion' : 'get2pay1',
                        'group' : None,
                        'amount' : 9
                 },
                 '10015' : { 
                        'name' : 'Diced Beef 400G', 
                        'price' : 4.50,
                        'unit' : 'pieces', 
                        'promotion': 'get4pay3',
                        'group' : 4,
                        'amount' : 14
                }}

            def listitems(dct):
                """
                inputs dictionary of stock and prints a lovely table showing all the items with info
                """
                print("\n")
                print(" {0:^5} | {1:&lt;38} | {2:^7} | {3:^11} ".format("Ident", "Product", "Price", "Amount"))
                print("-" *7 + "+" + "-" * 40 + "+" + "-" * 9 + "+" + "-"*12 + "+")
                for key in sorted(dct):
                    print(" {:^5} | {name:&lt;38} | {price:&gt;5.2f} £ |  {amount:&gt;} {unit:&lt;14}".format(key, **dct[key]))
                return


            #main code of function



            basket = dict()
            quantity = input("Number of items? ")
            #amount = 6
            ident = input("Indentification number? ")
            #ident = "10011"

            listitems(stock)


            try:
                quantity = int(quantity)
            except ValueError:
                try:
                    quantity =  float(quantity)
                except ValueError:
                    print("You have entered a invalid amount")       

            try:
                ident = str(ident)
            except ValueError:
                print("you have entered a invalid indent.")


            #print("amount is ", quantity)
            #print("amount in stock ", stock[ident]["amount"])



            if quantity &gt; 0:
                if quantity &lt; stock[ident]["amount"]:

                    basket[ident] = stock[ident] #adding the product tp the basket. 

                    basket[ident]["amount"] = quantity

                    stock[ident]["amount"] = stock[ident]["amount"] - quantity





            listitems(stock)
            listitems(basket)


            print("amount is ", quantity)
            print("amount in stock ", stock[ident]["amount"])
            print("amount in basket", basket[ident]["amount"])
</code></pre>