Skip to content

Instantly share code, notes, and snippets.

@Rainyan
Last active May 7, 2023 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rainyan/445ee2dc8230fdfdd2ff1169c4043bcc to your computer and use it in GitHub Desktop.
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 sys
def get_aspect_ratio(width: int, height: int) -> tuple[int, int]:
"""Return the aspect ratio of a screen resolution."""
a, b = width, height
while b != 0:
temp = b
b = a % b
a = temp
greatest_common_divisor = a
return (
int(width / greatest_common_divisor),
int(height / greatest_common_divisor)
)
if __name__ == "__main__":
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