Python Forum
LCM with recursion ( least common multiple)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LCM with recursion ( least common multiple)
#1
When i run this code python shell shows nothing

in '2.txt' 2 numbers " 21,53"
# least common multiple
def lcm(a,b):
 with open('2.txt') as f:
    a, b = [int(x) for x in next(f).split(',')]
    array = [[int(x) for x in line.split(',')] for line in f]
    m = a*b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a+b)

 print("a=%d ; b=%d ; LCM=%d"%(a,b,lcm(a, b)))
Reply


Messages In This Thread
LCM with recursion ( least common multiple) - by foxman322 - May-25-2019, 12:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  GCF function w recursion and helper function(how do i fix this Recursion Error) hhydration 3 2,590 Oct-05-2020, 07:47 PM
Last Post: deanhystad
  Least Common multiple python minko 5 2,717 Aug-18-2020, 02:54 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020