Explain meaning | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Explain meaning

Please someone explain to me what 'if not i%2==0' is and how it's used

30th Mar 2020, 5:19 AM
Nasrat Yusuf Ahmed
Nasrat Yusuf Ahmed - avatar
4 Answers
+ 4
From the use of 'i' I assume that this was a condition in a "for loop", more specifically, one designed to find whether a number in the list or string literal is even or not. If this is the case, remember that the "%" operator divides the left operand (value) by the right operand (divisor) but returns the remainder of the division. In the case you just showed, it will divide any value by 2 and if it is even, it should return the value of zero. I really hope this helps 🙈... EDIT: The presence of "not" before that condition indicates that it is checking if the value is "not" even.
30th Mar 2020, 7:46 AM
Zikora
Zikora - avatar
0
Hello! remember (or look for) from a math course, in which cases the remainder of dividing a number by two is zero?
30th Mar 2020, 5:45 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
'If i%2==0' , % is modullo which returns the remainder when i is divided by 2. So each time i is divided by 2 and the remainder is zero , this 'i' should be only even numbers. But the 'not' before the statement makes it false. So 'if i % 2 == 0 ' is true Not ' if i % 2 == 0' is false. Therefore 'i' should be odd numbers
30th Mar 2020, 11:57 AM
okafor Emmanuel
0
i%2=0 separately means that 'i' is an even number (because it is divisible by 2 or in another word it has no remainder when you divide it by 2) And when you have "if i%2==0", it means to check if i%2=0 is true or not And finally with having "not" before it, if condition will returns true only if 'i' is not divisible by 2 (not reverses condition meaning)
1st Apr 2020, 3:33 AM
Honey