Skip to content

Instantly share code, notes, and snippets.

@Rainyan
Last active June 2, 2025 01:03
Show Gist options
  • Select an option

  • Save Rainyan/445ee2dc8230fdfdd2ff1169c4043bcc to your computer and use it in GitHub Desktop.

Select an option

Save Rainyan/445ee2dc8230fdfdd2ff1169c4043bcc to your computer and use it in GitHub Desktop.
Return the aspect ratio of a screen resolution.
#!/usr/bin/env python3
import math
import sys
def get_aspect_ratio(width: int, height: int) -> tuple[int, int]:
"""Return the aspect ratio of a screen resolution."""
greatest_common_divisor = math.gcd(width, height)
return (int(width / greatest_common_divisor), int(height / greatest_common_divisor))
if __name__ == "__main__":
if len(sys.argv) != 3:
print(f"Usage: python3 {sys.argv[0]} <width> <height>")
sys.exit(1)
print(get_aspect_ratio(int(sys.argv[1]), int(sys.argv[2])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment