I understand that it is necessary to divide by 2 and look at the rest. That's what I was trying to do.
if ( not line%2 ): print 'chek true'
I understand that it is necessary to divide by 2 and look at the rest. That's what I was trying to do.
if ( not line%2 ): print 'chek true'
This option is also possible:
for x in (0, 1, 2, 3, 4): if not x & 1: print "%d is even" % x
for x in (0, 1, 2, 3, 4): if x % 2 == 0: print "%d is even" % x
If you need not evenness, but oddness, respectively, x % 2 != 0
.
%
passed to the right less. - drdaemanx % 2
it scolds like that, then x is a string, so yes, the problem is in types. For them, the operator %
has another meaning not related to the remainder of the division. - drdaeman for x in range(000000, 1000000000): if x % 2 == 0: print(Chet) else: print(Nechet)
number = int(input("Введите число: ")) if (number/2): print("Четное число") else: print("Нечетное число")
number = int(input("Введите число: ")) if (number%2 == 0): print("Четное число") else: print("Нечетное число")
number = int(input("Введите число: ")) if (number%2 > 0): print("Не чётное число =(") else: print(number+2)
> 0
, but not == 1
/ != 0
? Why print(number+2)
? - vp_arthSource: https://ru.stackoverflow.com/questions/30653/
All Articles