SHARE
TWEET

Python LCD

a guest Feb 23rd, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Format your inputs with a : and then a space,
  2. # it makes them nicer to read :)
  3. a = int(input("Enter the first denominator: "))
  4. b = int(input("Enter the second denominator: "))
  5.  
  6. # Separate your code that "arranges the world"
  7. # to avoid repeating your "main logic"
  8. if a > b:
  9.     x = a
  10.     y = b
  11. else:
  12.     x = b
  13.     y = a
  14.  
  15. # This is the "main logic"
  16. # because we already figured out whether a or b
  17. # was the biggest, we don't have to think about
  18. # it again here.
  19. factor = 1
  20. while x * factor % y != 0:
  21.     factor += 1
  22.  
  23. # Python's "string interpolation", a fancy way
  24. # for saying, shoving one string into another,
  25. # makes everything a bit easier to read :)
  26. lcd = x * factor
  27. print "The LCD of %d and %d is %d" % (a, b, lcd)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top