 Can you help me with this line of code what is the (%) doing? | SoloLearn: Learn to code for FREE!

+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)

+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. ... 👌

+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"

+8

https://www.sololearn.com/learn/Python/2273/

+5

DeadEye UNT No problem keep learning and growing 😊

+3

This is the first time in my life using big words like remainder of a division

+3

DeadEye UNT it is wrong Pls read the answer ofJulia Shabanova 1.25 % 5 = 1.25 and not 0.25

+3

DeadEye UNT You changed it now Earlier it was 1.25%5 Don't try to fool me 🙁

+3

Namit Jain: 😅😊☺️ You are welcome sir 👍🏼

+2

search for "mod" key example: 10 mod 6 gives you 4

+2

DeadEye UNT Nooo Python uses / for ÷ And % is a different operator to find the remainder and not the quotient

+2

👑Tchybooxuur! Great explanation sir!👍👌💃👦

+1

I thank you all for helping me with this 👍

+1

Printing EVEN NUMBERS I mod 2 = odd + 1 = EVEN 🙄

+1

You can write: for i in range(10): if i % 2: #1 is int value of True print(i)

+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

+1

Mod sign in any programming language with tha varible wich stores the remainder

+1

Yes in math and in programming also

0

How do i type that into my calculator

0

1.25%5 =0.25 1.25÷5=0.25 is it this ?