0

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.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by lukerobi
0

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
>>>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.