Skip to content Skip to sidebar Skip to footer

Doctest Failing Inspite Of Having Correct Output

My function is def validate_latitude(lat): '''Enforce latitude is in range >>> validate_latitude(65) 65 >>> validate_latitude(91) 90 >&

Solution 1:

In these two lines:

>>>validate_latitude(-91)
-90    

You have a Tab character before the - in -90, and four space characters after the 0. When doctests runs this code the extra whitespace is of course not produced, so the equality comparison fails.

Good editors, e.g. vim, have ways to highlight trailing spaces, and stray tabs, so that you don't fall afould of such accidents. Not sure what editor you're using or how you have set it up, so it's hard to give more specific advice (besides the obvious one of ensuring you use an editor WITH such capabilities, and enable the capabilities in question;-).

Solution 2:

Whitespace?

If I highlight your output, I can see additional whitespace following the "Expected" value. Not sure whether this is relevant or not.

Post a Comment for "Doctest Failing Inspite Of Having Correct Output"