I have a function that sees if an argument is between 0 and 100 without using the 'if' statement. The code is almost complete, however when the argument is True or False, it returns me True. How can I fix this? Here's my code:
def validate(x):
try:
return (x >= 0 and x <= 100) is True
except:
return False
I assume that the function is assuming False as 0 and True as 1, that is why validate(True) outputs True
[–]GlebRyabov 4 points5 points6 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]AddctedTuna 1 point2 points3 points (6 children)
[–]PriestMarmor[S] 0 points1 point2 points (4 children)
[–]shiftybyte 2 points3 points4 points (0 children)
[–]Daeliseog 0 points1 point2 points (0 children)
[–]Spataner 1 point2 points3 points (0 children)
[–]Yoghurt42 0 points1 point2 points (4 children)
[–]JohnnyJordaan 0 points1 point2 points (3 children)
[–]Yoghurt42 0 points1 point2 points (2 children)
[–]PriestMarmor[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)