Reputation: 176
Hello people, I've got a problem with my code. For some reason the values are not converted to integers from strings and are not adding up. Here is my code.
def SumOfState(i,j):
cf=readPopest(file1)
sum2=[]
sum7=[]
Diff=0
for y in range((j)):
StateList=str(cf[y+i]).split(',')
sum2.append(StateList[2])
sum7.append(StateList[7])
results2 = [int(i) for i in sum2]
results7 = [int(i) for i in sum7]
print sum(results2)
print sum(results7)
Error message : Inappropriate argument value (of correct type). An error occurred attempting to pass an argument to a function.
cf=readPopest(file1)
the code ^^ gives a list containing words and numbers. One element is taken % split into sublists.
Ive tried the int() function and the for loop variant of it.
suggest me an edit, please. Really appreciate any help. Thanks. -Addie Vanhala
Upvotes: 0
Views: 57
Reputation: 2611
I guess looking at you code, it is because sum2 and sum7 contain non integers, probably because some part of file1 (accessed though readPopest) is non int.
Upvotes: 1