sum_28

Given a list of ints, return true if the sum of all the 2’s in the list is exactly 8.

This exercise was taken from codingbat.com and has been adapted for the Python language. There are many great programming exercises there, but the majority are created for Java.

Test 1

Input:

[2, 3, 2, 2, 4, 2]

Output:

True

Test 2

Input:

[2, 3, 2, 2, 4, 2, 2]

Output:

False

Test 3

Input:

[1, 2, 3, 4]

Output:

False

Test 4

Input:

[2, 2, 2, 2]

Output:

True

Test 5

Input:

[1, 2, 2, 2, 2, 4]

Output:

True

Test 6

Input:

[]

Output:

False

Test 7

Input:

[2]

Output:

False

Test 8

Input:

[8]

Output:

False

Test 9

Input:

[2, 2, 2]

Output:

False

Test 10

Input:

[2, 2, 2, 2, 2]

Output:

False

Test 11

Input:

[1, 2, 2, 1, 2, 2]

Output:

True

Test 12

Input:

[5, 2, 2, 2, 4, 2]

Output:

True