dimanche 13 juin 2021

for i in range(len(data)): TypeError: 'int' object is not callable [closed]

I am trying to have an if statement that allows the user to select which option they want to run. For some reason, when I add my search function inside of my if function, I'm getting the 'int' object is not callable error, however when my function isn't in enclosed in the if-statement, I am not getting the error.. I'm guessing it's because of something I'm forgetting to do or leaving out of the if-statement. I would love to have some insight as to why this is.

range = int(input("Would you like to search for a hwy mpg range(1), city mpg range(2), or search exact city/hwy mpg range(3): "))

cityCol = [a[7] for a in data]
hwyCol = [b[8] for b in data]
divisionCol = [c[2] for c in data]
yearCol = [d[0] for d in data]

search = []
if range == 1:
    hwyLow = int(input("Hwy Low Range: "))
    hwyHigh = int(input("Hwy High Range: "))
    if hwyLow in hwyCol and hwyHigh in hwyCol:
        for i in range(len(data)):     
            if hwyLow <= data[i][8] and hwyHigh >= data[i][8]:
                # search.append(tuple([*data[i]]))
                print(*data[i], sep =", ")
    else:
        print("No automobiles within that range :(")
else:
    cityLow = int(input("City Low Range: "))
    cityHigh = int(input("City High Range: "))
    if cityLow in cityCol and cityHigh in cityCol:
        for a in range(len(data)):     
            if cityLow <= data[a][7] and cityHigh >= data[a][7]:
                # search.append(tuple([*data[a]]))
                print(*data[a], sep =", ")
    else:
        print("No automobiles within that range :(")
    cityMPG = int(input("City MPG: "))
    hwyMPG = int(input("Hwy MPG: "))
    if cityMPG in cityCol and hwyMPG in hwyCol:
        for a,b in enumerate(range(len(data))):     
            if cityMPG == data[a][7] and hwyMPG == data[b][8]:
                # search.append(tuple([*data[a]]))
                print(*data[a], sep =", ")
    else:
        print("No automobiles within that range :(")

Aucun commentaire:

Enregistrer un commentaire