Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Format your inputs with a : and then a space,
- # it makes them nicer to read :)
- a = int(input("Enter the first denominator: "))
- b = int(input("Enter the second denominator: "))
- # Separate your code that "arranges the world"
- # to avoid repeating your "main logic"
- if a > b:
- x = a
- y = b
- else:
- x = b
- y = a
- # This is the "main logic"
- # because we already figured out whether a or b
- # was the biggest, we don't have to think about
- # it again here.
- factor = 1
- while x * factor % y != 0:
- factor += 1
- # Python's "string interpolation", a fancy way
- # for saying, shoving one string into another,
- # makes everything a bit easier to read :)
- lcd = x * factor
- print "The LCD of %d and %d is %d" % (a, b, lcd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement