I am trying to find the lcd of all numbers in a list. My code is as follows:
from math import lcm
l = [1, 2, 3, 4, 5]
print(lcm(l)) #Supposed to calculate lcm of 1, 2, 3, 4, and 5
But it throws this error:
TypeError: 'list' object cannot be interpreted as an integer
After some searching, I found out that you have to input it like multiple arguments. So something like lcd(1, 2, 3, 4, 5)
would work.
How do I do this?
I had to iterate through every number in the list, but it takes a lot of time:
from math import lcm
l = [1, 2, 3, 4, 5]
n = 1
for x in l:
n = lcm(x, n)
print(n)
You need to sign in to view this answers
Leave feedback about this