Python error: TypeError: '_csv.reader' object is not subscriptable
Question: I am working on creating a change calculator that has to output a result
similar to this:

    
    
    {'TWENTY':1, 'TEN':1, 'FIVE':1, 'PENNY’ : 2}
    {‘ONE’:1,'FIVE':1}
    {‘ONE’:1}
    {'PENNY':4,'NICKEL':1}
    

I am having issues with reading the data and accessing the indices because I
have never worked with reading a .csv file before. I think the logic of my
calculator should be fine. I realize there are more efficent ways to code it
but I am on a time limit and this seemed logical to me. Any help is
appreciated.

Thanks

    
    
    enter code here__author__ = 'austincolaizzi'
    
    import csv
    
    print("Enter in your file name: ")
    
    file1 = input(" ")
    
    txt1 = open(file1)
    
    
    csv_txt1 = csv.reader(txt1)
    
    #for row in csv_txt1:
        #print (row[0:2])
    
    
    difference = 0
    remainder = 0
    change = {
        'Penny': 0,
        'Nickel': 0,
        'Dime': 0,
        'Quarter': 0,
        'Half Dollar': 0,
        'One': 0,
        'Two': 0,
        'Five': 0,
        'Ten': 0,
        'Twenty': 0,
        'Fifty': 0,
        'Hundred': 0,
    }
    
    for row in csv_txt1:
        if row[0] == row[1]:
            print ("You had exact change")
        elif row[0] > row[1]:
            print ("You need more money to purchase this")
    else:
        difference = csv_txt1[1] - csv_txt1[0]
        if difference % 100 == 0:
            remainder = remainder
        elif difference % 100 != 0:
            change['Hundred'] = difference / 100
            remainder = difference % 100
        elif remainder % 50 == 0:
            remainder = remainder
        elif remainder % 50 != 0:
            change['Fifty'] = remainder / 50
            remainder = remainder % 50
        elif remainder % 20 == 0:
            remainder = remainder
        elif remainder % 20 != 0:
            change['Twenty'] = remainder / 20
            remainder = remainder % 20
        elif remainder % 10 == 0:
            remainder = remainder
        elif remainder % 10 != 0:
            change['Ten'] = remainder / 10
            remainder =  remainder % 10
        elif remainder % 5 == 0:
            remainder = remainder
        elif remainder % 5 != 0:
            change['Five'] = remainder / 5
            remainder = remainder % 5
        elif remainder % 2 == 0:
            remainder = remainder
        elif remainder %2 != 0:
            change['Two'] = remainder / 2
            remainder = remainder % 2
        elif remainder % 1 == 0:
            remainder = remainder
        elif remainder %1 != 0:
            change['Two'] = remainder / 1
            remainder = remainder % 1
        elif remainder % int(.50) == 0:
            remainder = remainder
        elif remainder % int(.50) != 0:
            change['Two'] = remainder / int(.50)
            remainder = remainder % int(.50)
        elif remainder % int(.25) == 0:
            remainder = remainder
        elif remainder % int(.25) != 0:
            change['Two'] = remainder / int(.25)
            remainder = remainder % int(.25)
        elif remainder % int(.10) == 0:
            remainder = remainder
        elif remainder % int(.10) != 0:
            change['Two'] = remainder / int(.10)
            remainder = remainder % int(.10)
        elif remainder % int(.05) == 0:
            remainder = remainder
        elif remainder % int(.05) != 0:
            change['Two'] = remainder / int(.05)
            remainder = remainder % int(.05)
        else:
            remainder = remainder / int(.01)
    
    
    for key in change:
        if change[key] >= 1:
            print (change[key])
    


Answer: In the line after your else statement, you have `csv_txt1[1] - csv_txt1[0]`.

This should be `row[1] - row[0]`, as you have earlier.

Note you should have posted the traceback, which would have made this easier
to debug as it shows the exact line the error occurred on.

