'int' object not subscriptable error
<pre><code>while 1 == 1:
    import csv 
    from time import sleep
    import sys 
    bill = 0 
    with open('list2.txt') as csvfile: 
        readCSV = csv.reader(csvfile, delimiter = ",") 
        GTINs = [] 
        products = [] 
        prices = [] 
        for row in readCSV: 
            GTIN = row[0] 
            product = str(row[1]) 
            price = float(row[2]) 

            GTINs.append(GTIN) 
            products.append(product)
            prices.append(price)

    x = 1
    print("Welcome to the GTIN shop!")
    while x == 1:
        try:
            sleep(1) 
            print("Please input the 8 digit GTIN code")
            sleep(0.5)
            GTIN0 = GTIN[0]
            GTIN1 = GTIN[1]
            GTIN2 = GTIN[2]
            GTIN3 = GTIN[3]
            GTINx = input("--&gt; ")
</code></pre>

<p>The error brought up here is that on the lines GTIN0 = GTIN[0] etc, the 'int' object not subscriptable, I can't work out how to fix it, it used to work before.</p>

<p>For reference, here is "list2.txt".</p>

<pre><code>45112454,Milk,1.29
55555555,Bread,0.49
87595376,Milkshake,1.99
</code></pre>

<p>The next error comes up here (continuing from last segment):</p>

<pre><code>            GTINx = input("--&gt; ")
            if GTINx == GTIN0: 
                product1 = products[0] 
                price1 = prices[0]
                x = 2 
            elif GTINx == GTIN1:
                product1 = products[1]
                price1 = prices[1]
                x = 2
            elif GTINx == GTIN2:
                product1 = products[2]
                price1 = prices[2]
                x = 2
            elif GTINx == GTIN3: (this one is just here for if another one is added)
                product1 = products[3]
                price1 = prices[3]
                x = 2
            else:
                print("Have another go")
        except: 
            print("ERROR - Try Again")
</code></pre>

<p>To retrieve milk, the code is 7. For bread the code is 8, and for milkshake, the code is 9. I have no idea where python got these numbers from...</p>

<pre><code>while x == 3:
    try:
        sleep(1)
        print("So you would like", number, product1, "?") 
        sleep(0.5)
        confirmation = input("Please enter \"YES\" or \"NO\": --&gt; ") 
        if confirmation == ("YES") or ("Yes") or ("yes"): 
            x = 4
        elif confirmation == ("NO") or ("No") or ("no"):
            x = 1 
        else:
            sleep(0.5)
            print("Have another go")
    except:
        print("ERROR - Try Again")
</code></pre>

<p>So, this was supposed to end that loop, and send them back to the start if they said no (relooped via while 1 == 1:) but, it acts as if they said yes, no matter what was typed.</p>

<p>Next is a similar issue...</p>

<pre><code>while x == 4:
    try:
        cost = price1 * number 
        bill = bill + cost 
        print("The cost is", cost) 
        sleep(5) 
        print("Would you like to purchase anything else?") 
        sleep(0.5)
        anythingelse = input("Please enter \"YES\" or \"NO\": --&gt; ")
        sleep(1)
        if anythingelse == ("YES") or ("Yes") or ("yes"):
            x = 1 
        elif anythingelse == ("NO") or ("No") or ("no"):
            x = 5 
        else:
            sleep(0.5)
            print("Have another go")
    except:
        print("ERROR - Try Again")
</code></pre>

<p>Again, it answers yes, no matter what is inputted.</p>

<p>Sorry for the spam, thanks for any help that I get.</p>

<p>In relation with the 'if' comparison issue, I would recommend you to firstly remove the Upper format from the string and then compare. It would be then more idiomatic and also youre problem would be solved:</p>

<pre><code>if anythingelse.lower() == ("yes"):
        x = 1 
elif anythingelse.lower() == ("no"):
        x = 5 
else:
        sleep(0.5)
        print("Have another go")
</code></pre>

python python-3.x csv