print( sum_nums([[2, 12, 2], [12, 5, 100, 9]], 10) ) # 18
print( sum_nums([[2, 12, 2], [10, 5, 10, 9]], 10) ) # 18
print( sum_nums([[2, 12, 2], [10, 5, 10, 9]], 0) ) # 0
print( sum_nums([], 10) ) # 0
Module 13 Assignments
Programming Problems
Programming Problems should be submitted to gradescope.
Programming Problem 25
Due date: Dec 3, Tuesday at 7pm
Write a Python function that does the following:
- Its name is
sum_nums
- It takes two arguments: a list of list (2D list) of
integers
andn
an integers - It iterates through all of the numbers, and sum all of the ones whose value is less than
n
- It returns the sum
Test cases:
Name the program sums.py
. Make sure that gradescope gives you the points for passing the test case.
Programming Problem 26
Due date: Dec 3, Tuesday at 7pm
Write a Python function that does the following:
- Its name is
longest_string
- It takes one argument: a list of dictionaries
- The keys in each dictionary could be of various types, but you may assume that the values will be strings
- It returns the longest string value from all of the dictionaries in the list
Test cases:
= [{'a':'horse', 'b':'caterpillar'}, {'a':'camp', 'c':'joker'}]
data print( longest_string(data) ) # caterpillar
= [{1:'abc', 5:'onetwothree'}, {2:'abcd'}, {7:'one two three'}]
data print( longest_string(data) ) # one two three
Name the program longest.py
. Make sure that gradescope gives you the points for passing the test case.