Post

@PythonPr Bug is in the logic 👇
x % 2 == False works, but it’s confusing.
Should be: x % 2 == 0 for clarity.
English

@PythonPr For x = 3:
x % 2 = 1
1 == False → False → first if is skipped
elif x % 2 → 1 → True
So it print - even
English

@PythonPr The logic was reversed. The elif statement ain't necessary.
Should have been:
x = 3
if x % 2 == 0:
print("even")
else:
print("odd")
English

@PythonPr False is implied as 0 in python, x%2 (when x is 3)= 1, hence the condition for ‘if’ got false and it will move to elif. Elif is simply true. Hence, it will give odd for even value and vice versa.
English

@PythonPr There is no error, the code runs. The problem is bad logic and poor style. In if x % 2 == False and especially elif x % 2, the conditions rely on truthiness. x % 2 returns 0 or 1, so it works, but it is unclear and the even and odd outputs are reversed.
English

@PythonPr x = 3
if x % 2 == 1:
print("odd")
elif x % 2:
print("even")
else:
print("none")
Fixed it 😊
English

@PythonPr Logic is flipped 😅 even/odd conditions are wrong
English

@PythonPr 'even' will print since 3 % 2 is 1 (False would be 0). The first elif will print since x % 2 evaluates to True.
English

@PythonPr x % 2 == false is wrong logic, else: print(none)--% Unnecessary
English

@PythonPr x = 3
3 mod 2 is 1
in the if statement 1 or none zero value will evaluate to true so
if ( x % 2 == False ) : # value of 0
print("Even")
also "none" would never executed as mod 2 will result always in a 0 or 1 "False" or "True",
specific predicate - 1st vs implied on 2nd
English






