+ 2

what does this code mean?

for a in range (200): if (a%9 or a%2 ==0): continue print a,

4th Jul 2018, 2:09 PM
Venkatesh
8 odpowiedzi
+ 4
Venkatesh the bug is in line 2. try it like this if(a%9==0 or a%2==0): Don't forget ur print(a) is not in same block as the if condition. Here, the print(a) is technically acting as an else statement. --With this: if (a%9 or a%2 ==0): continue print a he(python) will ignore the value of a whenever the condition of the if statement is true and print when false. Now when a==9 a%9 == 0 a%2 == 1 and 0 or 1 != 0(condition is false) so 9 is printed. same goes to the other values of a that was printed. And plz remove the comma in line 4 else python'll bite.
4th Jul 2018, 5:31 PM
E_E Mopho
E_E Mopho - avatar
+ 3
but the output is all divisible by 9 9 27 45 63 81 99 117 135 153 171 189. . How?
4th Jul 2018, 4:22 PM
Venkatesh
+ 2
for a in range (200) iterates from 0 to 200 if (a%9 or a%2 == 0): not divisible by 9 or 2 (even numbers) continue Continues print a, outputs the value of a
4th Jul 2018, 3:23 PM
Agent
Agent - avatar
+ 1
iterates through numbers from 0 to 200, and doesn't print out even numbers or numbers divisible by 9
4th Jul 2018, 3:06 PM
hinanawi
hinanawi - avatar
+ 1
if do you want the number is not divede by 2 or 9 ... use the (), don't forget about the precedence order ex 18 the first sentence to check because of the precedence is : 18%2== 0 >> True >> 1 18%9 >> 0 >> False so it enters in the if and don't print ex 27 27%2 == 0 >> False >> 0 27%9 >> 0 0 or 0 false, so it's don't enter in the if
4th Jul 2018, 4:49 PM
Jefferson Fingolo
Jefferson Fingolo - avatar
+ 1
code will print number from 0 to 200 which are not divisible by 2 and 9
5th Jul 2018, 7:43 AM
Vimlesh Kumar
Vimlesh Kumar - avatar
0
simple, in fact the code does this .... it check if the number is divided by 2 (is even)... if not ... it multiple by 9.. so the output is (9*1) then 27(9*3)... etc
4th Jul 2018, 4:47 PM
Jefferson Fingolo
Jefferson Fingolo - avatar
0
try like below, it should work for a in range (200): if (a%9 ==0 or a%2 ==0): continue print a,
4th Jul 2018, 4:49 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar