How to check if a float value is a whole number in Python?
Answers
Answered by
1
We can use the modulo (%) operator. This tells us how many remainders we have when we divide x by y - expresses as x % y. Every whole number must divide by 1, so if there is a remainder, it must not be a whole number.
This function will return a boolean, True or False, depending on whether n is a whole number.
def is_whole(n):
if n % 1 == 0:
return True
else:
return False
This i given in 7th grade text book so just see whether this is applicable for you
and the ans is correct for sure
Hope its helps you
DO MARK BRAINLIEST
Similar questions