Computer Science

Given a tuple pairs = ((2, 5), (4, 2), (9, 8), (12, 10)), count the number of pairs (a, b) such that both a and b are even.

Python

Python Tuples

15 Likes

Answer

tup = ((2,5),(4,2),(9,8),(12,10))
count = 0
tup_length = len(tup)
for  i in range (tup_length):
    if tup [i][0] % 2 == 0 and tup[i][1] % 2 == 0:
        count = count + 1
print("The number of pair where both a and b are even:", count)

Output

The number of pair where both a and b are even: 2

Answered By

8 Likes


Related Questions