I have written a function to determine the height of a display, given a width and a format. The function operates recursively, if it cannot find a match for the given width and format while trying out a row of height values. The function works, if it finds a match before going into the recursion, but after that it always returns none and not the matching value pair. I am very confused as to why that is. Am I missing some principle here?
def getDisplayDimensions(width,FormatX,FormatY):
Format = float(FormatX)/FormatY
if FormatX < FormatY:
return "illegal format."
for height in range(1,int(width)+1):
if float(width)/height == float(Format):
return width,height
break
elif height == width:
getDisplayDimensions(float(width)-1,FormatX,FormatY)
# example call:
print getDisplayDimensions(801,16,9)