python
If a number num1 divides another number num2 evenly then num1 is a divisor of num2. For example, 2 is a divisor of 2, 4, 6, 8, but 2 is not a divisor of 1, 3, 5, 7, 9, 11, 13.
Write a function named count_divisors(m,n) that works as follows.
Example 1:
# We call the function with m = 2, n = 3
count = count_divisors(2, 3)
user input -> 1, 6, 5, -4, 7, 9, 12, stop. count = 2
user input -> -6, 2, 9, 16, 8, -5, stop. count = 4
Example 2:
# We call the function with m = 5, n = 2
count = count_divisors(5, 2)
user input -> 1, 6, 5, -4, 7, 9, 12, stop. count = 4
user input -> -6, 2, 10, 16, 8, -5, stop. count = 5
Program Code Screenshot
Program Sample Console Input/Output Screenshot
Program Code to Copy
def count_divisor(m, n):
count = 0
nums = input().split(", ")
for num in nums:
if(num == "stop"):
return count
num = int(num)
if(num % m == 0 or num % n == 0):
count += 1
print("count = ", count_divisor(2, 3))
Get Answers For Free
Most questions answered within 1 hours.