[Tutor] LCM
Shashwat Anand
anand.shashwat at gmail.com
Thu Oct 21 03:39:59 CEST 2010
On Thu, Oct 21, 2010 at 5:00 AM, Jacob Bender <benderjacob44 at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101021/0cce1385/attachment-0001.html>
More information about the Tutor
mailing list