A function that returns the number of divisors
Write code · Medium · §8.1, §8.2 Giving back
The code below counts the divisors of 12. Turn it into a function count_divisors(n) that takes n and returns the number of its divisors. Then print count_divisors(12), count_divisors(18), and count_divisors(12) + count_divisors(7), one per line in that order.
Starter code
count = 0
for i in range(1, 13):
if 12 % i == 0:
count += 1
print(count)Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.