Demande d'aide svp!

Ecrire un algorithme d’un module qui permet de remplir un tableau T (tableau n’est pas liste) par les facteurs premiers d’un entier N (Version récursive )

What have you tried?

def remplir(n):
global i, j
if (n % i)==0:
remplir( n//i)
for k in range (j):

nt(input('n= '))

Please wrap code in triple backticks to preserve the formatting:

if True:
    print(''Hello world!')

You can do that by selecting the code and then clicking the </> button.

The line:

nt(input('n= '))

should be:

n = int(input('n= '))

Try to use meaningful names for variable to make the code easier to understand. You’ll thank yourself if you return to the code in the future!

Try to avoid global variables; they are often more trouble than they’re worth.

For a truly recursive solution, I’d suggest something like this:

  • Create the array first and then call the function, passing the array, the index into the array, and the first possible factor.

  • The function would check to see whether there could be another more factors. If there aren’t any more, then return the count.

  • Otherwise, either put a factor into the array and then call itself or call itself with the next possible factor.

(Personally, I wouldn’t use recursion for this problem unless it was specifically required.)

The OP’s oriiginal problem spec seemed to require a recursive solution.

Cameron Simpson