What does ' if not i%2==0: ' means ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What does ' if not i%2==0: ' means ?

Python code

27th Mar 2020, 9:37 AM
Shubham Agarwal
Shubham Agarwal - avatar
15 Answers
+ 7
It means if i%2 !=0
28th Mar 2020, 7:20 AM
Wade
Wade - avatar
+ 3
If i%2==1: i%2 will only return a 0 or a 1 if not 0, then i%2==1 It could also be written as if i%2: PS: I am assuming you understand the % function. Please advise if this is not clear
27th Mar 2020, 9:44 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Shubham Agarwal How can we know a number is an even number, by dividing it by 2 and checking if it completely divides or leaves a remainder. 10 / 2 gives 5 with 0 remainder (10 is even) 13/2 gives 6 with 1 remainder(odd) There is an operator (%) just like * / + - it does something. It tells u the remainder. 13%2 = 1. So we check if something % 2 == 0 then its even, else its not.
27th Mar 2020, 11:03 AM
maf
maf - avatar
+ 2
:
28th Mar 2020, 7:21 AM
Wade
Wade - avatar
+ 1
If the remainder of I/2 ==0 i.e number is divisible by 2 is an even number. If the remainder is 1, it's an odd number
27th Mar 2020, 9:50 AM
Justus
Justus - avatar
+ 1
if number is not even
28th Mar 2020, 4:38 PM
Husniddin Berdiyew
Husniddin Berdiyew - avatar
+ 1
It is the same if i%2 != 0 for example i = 5 if not i % 2 == 0: print("HELLO") #This code prints 'HELLO' if i % 2 == 0: print("HELLO") #This code prints nothing if i % 2 != 0: print("HELLO") #This code prints 'HELLO'
29th Mar 2020, 8:39 AM
Mir-Abgar Abrahamyan
Mir-Abgar Abrahamyan - avatar
+ 1
If i divided by 2 doesn't equal 0, then do something ( if i % 2 !=0: )
29th Mar 2020, 9:19 AM
George Pavlov
George Pavlov - avatar
0
It means if number is odd
27th Mar 2020, 10:49 AM
nichdiomajadoch
0
% is a operator used to find the remainder after dividing two numbers and here in i%2 == 1 will be true if the remainder is 1 after dividing.
28th Mar 2020, 6:44 PM
Jay Prakash Pathak
Jay Prakash Pathak - avatar
0
You must first worry about the order of precedence, 1.- Parentheses 2.- mathematical operators 2.1.- division 2.2.-multiplication 2.3.-division 2.4.- floor division 2.5.-addition and subtraction 3.- bitwise operators 4.- comparison operators 5.- logical operators 5.1.- not 5.2.- and 5.3.- or After knowing that you apply 1) i should define it before with a number, and i% 2 will be the remainder of its result. 2) if result you compare it if it is equal to zero (i% 2 == 0) its result will be True (it can be seen equal to 1) or False (it can be seen equal to 0) 3) and the not, if it gives True it returns it False and if it is False it returns it True. 4) with the if statement, if it is true, that is, if all the previous result is True, it is carried out, otherwise, it does not allow you to make the statement that is within the if. I hope it has helped you. 😁😁
29th Mar 2020, 6:43 AM
Axel Rivero
Axel Rivero - avatar
0
if not i%2==0 can also be written as, if (i%2!=0) . i%2 gives the remainder obtained when i is divided by 2. So the expression stands true if the remainder of i when divided by 2 is not 0. Therefore, the expression stands true for all odd numbers because any odd number when divides with 2, leaves a remainder of 1
29th Mar 2020, 9:01 AM
Sai Nikhil Paruchuru
Sai Nikhil Paruchuru - avatar
0
if not i%2==0 can also be written as, if (i%2!=0) . i%2 gives the remainder obtained when i is divided by 2. So the expression stands true if the remainder of i when divided by 2 is not 0. Therefore, the expression stands true for all odd numbers because any odd number when divides with 2, leaves a remainder of 1
29th Mar 2020, 9:02 AM
Sai Nikhil Paruchuru
Sai Nikhil Paruchuru - avatar
- 1
it means 'if not even'
29th Mar 2020, 11:11 AM
anant krishna
anant krishna - avatar
- 1
If the remainder of i%2 is equal to zero then the number is an even number
29th Mar 2020, 11:18 AM
Rohit Das
Rohit Das - avatar