python - Counting factors in a list? -
python - Counting factors in a list? -
okay made list called numberslist, variable number = 20, count = 0, , spot = 0.
numberslist = range(1, 11) number = 20 count = 0 spot = 0. i want count numbers in list go 20. tried this:
while spot <= len(numberslist): if(number % int(numberslist[spot]) == 0): count = count + 1 spot = spot + 1 print count but keeps saying list index out of range. please help!
your index goes far @ lastly iteration of while loop. alter <= < , should work:
while spot < len(numberslist): or utilize for loop:
for in numberslist: if number % == 0: count += 1 python list count
Comments
Post a Comment