famguy74 - 1 year ago 44

Python Question

Unlike my question from earlier, I have no idea how to accomplish this task and write this function and don't have much code prepared. The goal is to "find out how many numbers # from 1 to n inclusive evenly divide n" when given a positive int. Any help would be appreciated here is the code I have so far

`def num_divisors(n):`

for i in n:

if n >= 1:

answer = i // n

return answer

I'm currently getting the error "'int' object is not iterable" for all test cases and here they are for reference:

Check that num_divisors( 1 ) returns 1.

Check that num_divisors( 12 ) returns 6.

Check that num_divisors( 100 ) returns 9.

Check that num_divisors( 360 ) returns 24.

Answer Source

The working code is following

```
def num_divisors(n):
count_d = 0
for i in range(1, n+1):
if n % i == 0:
count_d += 1
return count_d
```