NOTE: You may not use any functions from external modules loaded by \'import.\'
ID: 3791138 • Letter: N
Question
NOTE: You may not use any functions from external modules loaded by 'import.' In addition, you may not use dictionaries, list comprehensions, or other Python language features not yet taught in this class. The point of these exercises is to practice very basic components of programming.
Write a function primeDivisorsOf(num) that takes a positive integer as input and returns a list of that number's prime divisors. You may copy and use the numIsPrime function developed in class if you wish.
For example:
Explanation / Answer
def isprime(n):
if(n == 1):
return False
for i in range(2,n):
if(n%i == 0):
return False
return True
def primeDivisorsOf(n):
l = []
for i in range(2,n+1):
if(n%i == 0):
if(isprime(i)):
l.append(i)
print l
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.