CMU Coding Bootcamp
1def oddCount(L: list[int]) -> int:
2 return len([n for n in L if n % 2])
3
4def testOddCount():
5 print('Testing oddCount()...', end='')
6 assert(oddCount([]) == 0)
7 assert(oddCount([1]) == 1)
8 assert(oddCount([2]) == 0)
9 assert(oddCount([1,2,3,4,5,4,3]) == 4)
10 assert(oddCount([1,2,3,4,5,4,3,2]) == 4)
11 assert(oddCount([2,4,6,8,10,12,14]) == 0)
12 assert(oddCount([1,1,1,1,1]) == 5)
13 print('Passed!')
14
15def main():
16 testOddCount()
17
18main()