1) Write a function called divisors that takes two natural numbers m and n,
and returns a List object containing all natural numbers (starting from m,
and going down to 2) by which n is divisible. For example:

divisors(6, 6)

should return a List object equivalent to

List(6, List(3, List(2, Empty))), whereas

divisors(4, 6)

should return a List object equivalent to

List(3, List(2, Empty)).

Then, use this function as a helper to write the function is_prime, which
takes a natural number n and returns True if the number is a prime number,
and False otherwise. A number is prime if its only divisor greater than 1 is
the number itself (example: 2, 3, 5, 7, 11, 13, etc.). 0 and 1 are not
prime. For example:

is_prime(2) is_prime(3) is_prime(5) etc.

should return True, and all of

is_prime(0) is_prime(1) is_prime(4) etc. should return False.

Recommended Answers

All 2 Replies

does this help you?

>>> n = 10
>>> for i in range(1,(n + 1)):
	if n % i == 0:
		print '%i factors into %i' % (i, n)

		
1 factors into 10
2 factors into 10
5 factors into 10
10 factors into 10
>>>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.