0

I don't understand this python code, please anyone share the explanation how this code executeđŸ€·â€. {Code in the description}

list1 = [3 , 2 , 5 , 6 , 0 , 7, 9] sum = 0 sum1 = 0 for elem in list1: if (elem % 2 == 0): sum = sum + elem continue if (elem % 3 == 0): sum1 = sum1 + elem print(sum , end=" ") print(sum1) #Output:8 12 but how?? đŸ€·â€â™‚ïžđŸ€·â€â™‚ïž

3rd May 2021, 3:30 AM
G-5256
G-5256 - avatar
2 RĂ©ponses
+ 2
Code_with_gaurav... There is continue used in 1st if condition so on every even number (elem % 2 == 0) it will skip current iteration and move for next iteration. In 2nd if statement there is elem % 3 == 0 means whichever element is divisible by 3 that will be add. So here 3 and 9 is divisible by 3 So 3 + 9 = 12
3rd May 2021, 3:38 AM
AÍąJ
AÍąJ - avatar
0
Give me the answer
20th Nov 2024, 3:21 PM
Sandhya Saraswat
Sandhya Saraswat - avatar