Why second variation of the code does not work as expected by me? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why second variation of the code does not work as expected by me?

https://code.sololearn.com/ca3ovvO46Lwr/?ref=app

19th Dec 2019, 2:29 PM
kuzantiv
kuzantiv - avatar
3 Answers
+ 1
Look up negation of statements in logic. For the first code, a number will be printed if it is divisible by 5 and divisible by 7, i.e. if it is divisible by 35, and ignored otherwise. For the second code, a number will be ignored if it is not divisible by 5 and not divisible by 7 and printed otherwise. This is not the same as above. E.g. consider a number which is divisible by 5 but not divisible by 7. It is not divisible by 35, so would be ignored by the first code. However, since it is divisible by 5, the if statement in the second code is false, so the number gets printed. The same happens for a number that is divisible by 7 but not divisible by 5. To make the second code equivalent to the first, change the "and" in the if statement to an "or".
20th Dec 2019, 2:08 AM
Njeri
Njeri - avatar
+ 2
It's math, the opposite of this stateent: if P and Q Is this: if not P or not Q
19th Dec 2019, 2:38 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
Still didn't get,🤔🤔🤔
19th Dec 2019, 3:09 PM
kuzantiv
kuzantiv - avatar