Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. def calculate_aspect(width: int, height: int) -> str:
  2. def gcd(a, b):
  3. """The GCD is the highest number that evenly divides both width and height."""
  4. return a if b == 0 else gcd(b, a % b)
  5.  
  6. r = gcd(width, height)
  7. x = int(width / r)
  8. y = int(height / r)
  9.  
  10. return f"{x}:{y}"
  11.  
  12. calculate_aspect(1920, 1080) # '16:9'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement