-2
for x in xrange(12):
    if x % 2 == 1:
        continue
    print x

i know what it does, but the language doesn't make sense to me. In particular the second line is where i am lost.

Zack
  • 3
  • 2
  • 5
    % is a modulo operator. A detailed answer - http://stackoverflow.com/questions/4432208/how-does-work-in-python – gaganso Jun 11 '16 at 03:24
  • https://www.google.com/?gws_rd=ssl#q=%25 python or https://www.bing.com/search?q=%25+python immediately suggest useful links (either directly or in "Related searches"). You may want to consider using one of those sites in the future to perform some basic research before posting question. – Alexei Levenkov Jun 11 '16 at 03:28

1 Answers1

0

if x % 2 == 1 means "if x modulo 2 equals 1".

Modulo (or mod) is the remainder after division. So, for example:

3 mod 2 = 1
12 mod 5 = 2
15 mod 6 = 3

For x mod 2, you're there's a remainder if and only iff x is odd. (Because all even numbers are divisible by two with 0 remainder.) Likewise, odd numbers will always have a remainder of 1.

So x % 2 == 1 returns true if x is odd.

James Tanner
  • 1,542
  • 1
  • 11
  • 10