Data Structures & AlgorithmsModerateTCS NQT · counting

Problem: How many 2-digit numbers have both digits odd? Run the code.

Problem: How many 2-digit numbers have both digits odd? Run the code.
print(sum(1 for x in range(10, 100) if int(str(x)[0]) % 2 == 1 and int(str(x)[1]) % 2 == 1))
What is printed?
  1. A. 20
  2. B. 16
  3. C. 30
  4. D. 25

Correct answer: D. 25

Each digit is one of 1, 3, 5, 7, 9, giving 5 * 5 = 25 numbers.

More Coding Interview Problems questions

Exams that ask this topic