CS HW-2-7-2021:
l1=[1,2,3,4]
l2=[3,4,5,6]
write a python program that accepts 2 lists and add all the even numbers from
both lists which ever matchs
Answers
Answered by
2
Once both lists have been entered, we assign a variable to represent the sum of the even numbers that exist in both lists. To get the sum, we start a for loop, which is an iteration statement that performs repeated checking over a given range. We use a conditional statement to check if the element is present in the second list as well, and if it's divisible by 2. If it satisfies both conditions, it gets added to the variable earlier assigned to represent the sum.
We used as it accepts any data type and proceeds with the upcoming statements according to the data type.
Similar questions