Suppose we have a floating point number; we have to check whether the number is odd or even. In general, for integer it is easy by dividing the last digit by 2. But for floating point number it is not straight forward like that. We cannot divide last digit by 2 to check if it is odd or even.
So, if the input is like n = 200.290, then the output will be Odd though the last digit is divisible by 2.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(n) : s = str(n) flag = False for i in range(len(s) - 1, -1, -1) : if s[i] == '0' and flag == False : continue if s[i] == '.': flag = True continue if int(s[i]) % 2 == 0 : return "Even" return "Odd" n = 200.290 print(solve(n))