ratio might have the value "None" after this if/elif. Would be better to add an else: and raise ValueError with a clear user message.