0

hey i need a to write a program that when given an interger reduces it to prime factors. the interger is guarenteed to be less than 900

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by pyTony
0

What you can then tell about the biggest possible smallest factor, when you know that we are dealing only with integers? Give some effort first yourself.

0

def factor (n):
"""returns a list of the prime factors of interger n"""
factors = []
p = primes.generator() # yields an infinite list
while n > 1 :
x = p.next()
while n % x == 0:
n = n/x
factors.append (x)
return factors

0
def factor (n):
    """returns a list of the prime factors of interger n"""
    factors = []
    p = primes.generator() # yields an infinite list 
    while n > 1 :
        x = p.next()
        while  n % x == 0:
            n = n/x
        factors.append (x)
    return factors

Could you explain your logic, especially how line 4 works and why you wrote line 6 like you wrote it and did not use for. Could you kindly also use (CODE) like I did here in my reply in your posts of code.

What is your problem? You did not ask or post any error messages.

Edited by mike_2000_17: Fixed formatting

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.