Explanation:
Assign a value to num
num = 5
We set num = 5.
We will use this value for checking divisibility.
Create the list a
a = [5, 10, 11, 13]
This list contains four numbers:
5, 10, 11, 13
Initialize sum variable
s = 0
We create s to store the total of selected numbers.
Starting value = 0
Start loop — go through each value in list
for v in a:
The loop takes each value v from the list:
First: v = 5
Then: v = 10
Then: v = 11
Then: v = 13
Check divisibility using IF + continue
if v % num == 0:
continue
We check:
If v is divisible by num (5), skip it.
Check each:
v v % 5 Divisible? Action
5 0 Yes Skip
10 0 Yes Skip
11 1 No Add
13 3 No Add
continue means: skip the rest of the loop and go to the next number.
Add the non-skipped values
s += v
Only numbers NOT divisible by 5 get added:
s = 11 + 13 = 24
Print the final answer
print(s)
So the output is:
24


0 Comments:
Post a Comment