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' 

    6 answers 6

    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 

      http://ideone.com/2WMaT

      If you need not evenness, but oddness, respectively, x % 2 != 0 .

      • Speak TypeError: not all arguments converted during string formatting Type mismatch, yes? - hooko
      • I understand, this is already talking about some modification of my example? Then, please, the code in the studio - telepaths on vacation. This error appears if there were one number of placeholders in the line (% d and others like it), and the operator % passed to the right less. - drdaeman
      • Looks like I figured it out. If at x % 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) 
      • As for the minus, do not worry, it is given automatically because the code was not formatted. Where are Chet and Nechet defined? - 0xdb
       number = int(input("Введите число: ")) if (number/2): print("Четное число") else: print("Нечетное число") 
         number = int(input("Введите число: ")) if (number%2 == 0): print("Четное число") else: print("Нечетное число") 
        • 3
          How is your solution better than the existing ones here for more than five years? Put an educational minus. - AK
         number = int(input("Введите число: ")) if (number%2 > 0): print("Не чётное число =(") else: print(number+2) 
        • 3
          How is your solution better than the existing ones here for more than five years? - vp_arth
        • 2
          Why > 0 , but not == 1 / != 0 ? Why print(number+2) ? - vp_arth