Last active
June 2, 2025 01:03
-
-
Save Rainyan/445ee2dc8230fdfdd2ff1169c4043bcc to your computer and use it in GitHub Desktop.
Return the aspect ratio of a screen resolution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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