def chek(x):
if x%3==0:
return False
return True
a=sum([i for i in range(6) if chek(i)])
print(a)
Asked
Active
Viewed 49 times
-3

ShadowRanger
- 143,180
- 12
- 188
- 271

Rippar
- 23
- 3
-
1Why do you think the result should be 15? – Hymns For Disco Mar 20 '20 at 19:06
-
Because it is sum([1, 2, 4, 5]) – Ekrem Dinçel Mar 20 '20 at 19:07
-
From 0 to 5 how many numbers are divisible by 3? What are they? Should they be excluded from the total? – PM 77-1 Mar 20 '20 at 19:07
1 Answers
2
[i for i in range(6) if chek(i)]
produces [1, 2, 4, 5]
, omitting 0
and 3
because they have a remainder of 0 when divided by 3, and therefore are not included in the listcomp output. The sum of 1, 2, 4 and 5 is 12.

ShadowRanger
- 143,180
- 12
- 188
- 271