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
t=array([0]*100)
if (n % i)==0:
t[j]=i
j+=1
else:
i+=1
remplir( n//i)
for k in range (j):
print(t[k])
#programme_principal
i=2
j=0
n=i

nt(input('n= '))
remplir(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.

Cheers,
Cameron Simpson cs@cskk.id.au