0

why the output of this code is 4?

nums = [1, 2, 3, 4] res = 0 for x in nums: if (x % 2 == 0): continue else: res += x print(res)

12th Oct 2022, 7:53 PM
Mohamed Yousry
Mohamed Yousry - avatar
3 Answers
+ 3
i believe this code output the sum of the odd numbers from the list here 1+3
12th Oct 2022, 7:59 PM
Maximignonne
Maximignonne - avatar
+ 3
1 % 2 != 0 —> res = 0 + 1 2 % 2 = 0 —> continue 3 % 2 != 0 —> res = 1 + 3 print(res)
12th Oct 2022, 8:02 PM
Solo
Solo - avatar
+ 3
13th Oct 2022, 3:50 AM
Ipang