Computer Science, asked by Rohith4686, 1 year ago

How to check if a float value is a whole number in Python?

Answers

Answered by rahulmandviya
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