We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
TIP101 Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Given a dictionary with all-integer values, add up all values that are even.
1) Sum variable starts at 0 2) For each value in the dictionary's values: a) If the value is even, add it to the sum 3) Return the sum
values
def sum_even_values(dictionary): sum_even = 0 for value in dictionary.values(): if value % 2 == 0: sum_even += value return sum_even
Alternative Solution: Use bracket notation to access the dictionary's value
def sum_even_values(dictionary): sum_even = 0 for key in dictionary: if dictionary[key] % 2 == 0: sum_even += dictionary[key] return sum_even