0
Why second variation of the code does not work as expected by me?
3 Réponses
+ 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".
+ 2
It's math, the opposite of this stateent:
if P and Q
Is this:
if not P or not Q
0
Still didn't get,🤔🤔🤔