I keep getting the error 'int' object is not substitutable. I know my problem is within "def filaray()" I also know making "num" a list would be more efficient. However this is an assignment and I'm pretty sure we can only use array's. Is there a way I can fix my error while not making "num" a list?
The line num = random.randint(0,9)
sets num
to an int
, and so when fillaray
returns num
(assuming size > 0
), it is returning an int
, not a list, and this int
is then passed to totalOdds
and totalEvens
, which try to subscript it (i.e., do num[i]
) as though it were a list, which is an error. Presumably, what you want to do is to append the random int
s to the list num
instead of overwriting it, e.g., by doing num.append(random.randint(0,9))
.
array
type, but it's not frequently used. You're doing num = a random int so many times, then returning the last int. You're not constructing a list or an array at all. – Max May 4 '13 at 4:10[0]
is indeed a list. Can you give a precise error message? Where is the line/column of the error? – jpaugh May 4 '13 at 4:12num
is initialized as a list ([0]
) but then overwritten byrandom.randint
. Trynum.append(random.randint(0, 9))
instead. – Stjepan Bakrac May 4 '13 at 4:13