0
Could you please explain me this code? And how it is giving 258 as its output
for n in range(10): if (n%3==2): print (n,end="")
6 Answers
- 1
Bhanu Tripathi You need to revise the how loop works..
There in for loop,
for n in range(10) :
Means loop iterates by taking n value in range 0 to 9 (10-1), for each iteration, so n=0,1,2,3,4,5,6,7,8,9
So only, When n=2 or 5 or 8,
The if condition becomes true so print n value, otherwise don't...
Note: add related to tags like python, for, or %
Only so can you edit it...!
+ 1
2%3 results in remainder 2
Same for 5%3 and 8%3
+ 1
Here 2 is not divisible by 3 hence the modulo value is 2 only..
0
But I can't get (2%3) part..how can (2%3) be computed?
0
3*0=0 and remainder is 2 you can't do 3*1 since it will be greater than 2 ,I think that's how division works
0
I can't get you fully...