Can you help me with this line of code what is the (%) doing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can you help me with this line of code what is the (%) doing?

For i in range(10): If not i%2==0: print(i+1)

11th Aug 2020, 5:55 PM
DeadEye UNT
DeadEye UNT - avatar
30 Answers
+ 5
DeadEye UNT in most programming languages you'll find, `%` operator is called the modulo (or mod) operator or remainder operator used to derive the remainder of the division of typically 2 int objects. In other words, x % y (pronounced x modulo y or x mod y) is the remainder of the Euclidean division of x and y. Bonus tip: x is called the dividend and y the divisor Examples: 5 % 2 = 1 8 % 6 = 2 3 % 5 = 3 (take note of this) ...the mod value of a small number over a big number is the small number. More so, mod value of a number over zero throws a ZeroDivisionError. ... 👌
13th Aug 2020, 8:27 AM
👑 Tchybooxuur!
👑 Tchybooxuur! - avatar
+ 9
% gives the remainder of a division. for example: 10 % 6 (or 10 mod 6) ____ 6 | 10 | 1 6 - - - - 4 <---- remainder. Coming to your question: your if statement is checking for odd numbers, because we know that even numbers satisfies this equation (i%2==0) but however in your code, you have "not" infront of this equation and hence "not even" means "Odd"
11th Aug 2020, 6:06 PM
Rohit Kh
Rohit Kh - avatar
+ 5
DeadEye UNT No problem keep learning and growing 😊
11th Aug 2020, 6:12 PM
Rohit Kh
Rohit Kh - avatar
+ 3
This is the first time in my life using big words like remainder of a division
11th Aug 2020, 6:11 PM
DeadEye UNT
DeadEye UNT - avatar
+ 3
DeadEye UNT it is wrong Pls read the answer ofJulia Shabanova 1.25 % 5 = 1.25 and not 0.25
11th Aug 2020, 6:22 PM
Namit Jain
Namit Jain - avatar
+ 3
DeadEye UNT You changed it now Earlier it was 1.25%5 Don't try to fool me 🙁
11th Aug 2020, 7:12 PM
Namit Jain
Namit Jain - avatar
+ 3
Namit Jain: 😅😊☺️ You are welcome sir 👍🏼
13th Aug 2020, 10:05 AM
👑 Tchybooxuur!
👑 Tchybooxuur! - avatar
+ 2
search for "mod" key example: 10 mod 6 gives you 4
11th Aug 2020, 6:07 PM
Rohit Kh
Rohit Kh - avatar
+ 2
DeadEye UNT Nooo Python uses / for ÷ And % is a different operator to find the remainder and not the quotient
12th Aug 2020, 5:54 PM
Namit Jain
Namit Jain - avatar
+ 2
👑Tchybooxuur! Great explanation sir!👍👌💃👦
13th Aug 2020, 8:54 AM
Namit Jain
Namit Jain - avatar
+ 1
I thank you all for helping me with this 👍
11th Aug 2020, 6:15 PM
DeadEye UNT
DeadEye UNT - avatar
+ 1
Printing EVEN NUMBERS I mod 2 = odd + 1 = EVEN 🙄
12th Aug 2020, 3:26 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
% gives you remainder In this case it is printing the odd numbers from the range 0 to 9(include) Eg: 4 ) 23 (5 20 ___ 3 ___ This modulo division (%) gives the remainder as 3 if you give 23%4
13th Aug 2020, 4:15 AM
Siva Prasad Pothala
Siva Prasad Pothala - avatar
+ 1
Mod sign in any programming language with tha varible wich stores the remainder
13th Aug 2020, 5:40 PM
DEEPAK
DEEPAK - avatar
+ 1
Yes in math and in programming also
13th Aug 2020, 5:42 PM
DEEPAK
DEEPAK - avatar
0
I thank you
11th Aug 2020, 6:05 PM
DeadEye UNT
DeadEye UNT - avatar
0
How do i type that into my calculator
11th Aug 2020, 6:07 PM
DeadEye UNT
DeadEye UNT - avatar
0
1.25%5 =0.25 1.25÷5=0.25 is it this ?
11th Aug 2020, 6:08 PM
DeadEye UNT
DeadEye UNT - avatar
0
please utilize the calculator.
11th Aug 2020, 6:10 PM
Rohit Kh
Rohit Kh - avatar