python - TypeError: 'int' object does not support item assignment -
python - TypeError: 'int' object does not support item assignment -
why error?
a[k] = q % b typeerror: 'int' object not back upwards item assignment
code:
def algorithmone(n,b,a): assert(b > 1) q = n k = 0 while q != 0: a[k] = q % b q = q / b ++k homecoming k print (algorithmone(5,233,676)) print (algorithmone(11,233,676)) print (algorithmone(3,1001,94)) print (algorithmone(111,1201,121))
you're passing integer function a
. seek assign as: a[k] = ...
doesn't work since a
scalar...
it's same thing if had tried:
50[42] = 7
that statement doesn't create much sense , python yell @ same way (presumably).
also, ++k
isn't doing think -- it's parsed (+(+(k)))
-- i.e. bytcode unary_positive
twice. want k += 1
finally, careful statements like:
q = q / b
the parenthesis utilize print imply want utilize on python3.x @ point. but, x/y
behaves differently on python3.x on python2.x. looking @ algorithm, i'm guessing want integer division (since check q != 0
hard satisfy floats). if that's case, should consider using:
q = q // b
which performs integer partition on both python2.x , python3.x.
python typeerror
Comments
Post a Comment