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
You are not actually returning the recursive call result:
elif height == width:
getDisplayDimensions(float(width)-1,FormatX,FormatY)
Add return
there:
elif height == width:
return getDisplayDimensions(float(width)-1,FormatX,FormatY)
Without the return
the outer call just ends and returns the default None
instead.
Demo:
>>> 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:
... return getDisplayDimensions(float(width)-1,FormatX,FormatY)
...
>>> print getDisplayDimensions(801,16,9)
(800.0, 450)