Tell us what’s happening:
This is about last Friday’s challenge — Wider aspect ratio. (Python)
While it is probably not the most elegant, I wrote it without importing any library, my code returns the correct responses and in the requested format. But the testing is failing ![]()
Your code so far
def get_wider_aspect_ratio(a, b):
wider = []
# extract numbers from text into list
a_list = a.split('x')
b_list = b.split('x')
# determine the wider ratio
if (int(a_list[0]) / int(a_list[1])) > (int(b_list[0]) / int(b_list[1])):
wider = [int(a_list[0]), int(a_list[1])]
else:
wider = [int(b_list[0]), int(b_list[1])]
# reduce to lowest ratio numbers
red_wider = reducer(wider)
# return as text
return f'"{red_wider[0]}:{red_wider[1]}" '
def reducer(dim):
result = 0
larger_a = True if dim[0] > dim[1] else False
if larger_a:
first = dim[0]
second = dim[1]
check = dim[1]
else:
first = dim[1]
second = dim[0]
check = dim[0]
while check >= 0:
if check == 0:
return None
if first % check == 0 and second % check == 0:
if larger_a:
return [first // check, second // check]
else:
return [second // check, first // check]
else:
check -= 1
print(get_wider_aspect_ratio("1920x1080", "800x600"))
print(get_wider_aspect_ratio("1080x1350", "2048x1536"))
print(get_wider_aspect_ratio("640x480", "2440x1220"))
print(get_wider_aspect_ratio("360x640", "1080x1920"))
print(get_wider_aspect_ratio("3440x1440", "2048x858"))
print(get_wider_aspect_ratio("12345x61234", "12534x51234"))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5 Safari/605.1.15 Ddg/26.5
Challenge Information:
Daily Coding Challenge - Wider Aspect Ratio
https://www.freecodecamp.org/learn/daily-coding-challenge/2026-05-29