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.
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
Related Questions
Create a tuple containing the squares of the integers 1 through 50 using a for loop.
Create a tuple ('a', 'bb', 'ccc', 'dddd', … ) that ends with 26 copies of the letter z using a for loop.
Write a program that inputs two tuples seq_a and seq_b and prints True if every element in seq_a is also an element of seq_b, else prints False.