check even or odd in single line 1

check even or odd in single line

n=9
print("Odd" if n%2 else "Even")

Here is what the above code is Doing:
1. n%2 returns 1 if n is odd and 0 if n is even.
2. if n%2 returns 1, then the if condition is True and “Odd” is printed.
3. if n%2 returns 0, then the if condition is False and “Even” is printed.

Similar Posts