I need to write a recursive function, which finds the least common multiple elements of the list with n length. My code:
import random
def random_num(n):
return [random.randint(-20,20) for i in range(n)]
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def my_nok(n,m):
return (n/gcd(n,m))*m
The first problem is: my functions work only with two arguments, not with the whole list.
The second problem: i need to have the only one function for finding the least common multiple (my code contains two for that).
Aucun commentaire:
Enregistrer un commentaire