On Thu, Oct 21, 2010 at 5:00 AM, Jacob Bender <benderjaco...@gmail.com>wrote:
> Hello all, > > I was wondering if you could please help me with an issue I'm having with > my program. I'm not fond of LCM(Least Common Multiples), and I decided to > make a program that deals with them. Here's the code: > > thing = raw_input("What is the first number?\n\n") > > thing2 = raw_input("What is the second number?\n\n") > > int(thing) > int(thing2) > > x = 1 > > thing3 = x/thing > thing4 = thing2/x > > def calc(): > while True: > > if isinstance(thing3, int) == True: > if isinstance(thing4, int)== True: > print "The LCM is" > print x > raw_input() > break > else: > x + 1 > calc() > > > else: > x + 1 > calc() > > calc() > > Why this much bother. Use: import fractions solution = int(thing) * int(thing2) / ( fraction.gcd(int(thing), int(thing2)) ) The property being used is for two numbers a,b ; lcm(a, b)* gcd(a, b) = a * b -- ~l0nwlf
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor