def main():
= sum_all([])
value assert value == 0, f"expected return value was 0, but function returned {value}"
= sum_all([0, 0, 0, 0, 0])
value assert value == 0, f"expected return value was 0, but function returned {value}"
= sum_all([1, -1, 2, -2, 3, -3])
value assert value == 0, f"expected return value was 0, but function returned {value}"
= sum_all([1, 2, 3, 4, 5])
value assert value == 15, f"expected return value was 15, but function returned {value}"
print("All tests passed.")
main()
Module 6 Assignments
Short Project 05
Due date: Oct 8, Tuesday at 7pm
Short Programming projects are submitted during our weekly 45-minute in-person lab sessions. Each lab sessions is guided by two TAs. The instructions for the short project will be available only during the lab sessions. To schedule your lab session go to the weekly lab session spreadsheet.
Programming Problems
Programming Problems should be submitted to gradescope.
Programming Problem 11
Due date: Oct 8, Tuesday at 7pm
Write a Python function that does the following:
- Its name is
sum_all
- It takes a list of numeric values as argument:
numbers
- It returns the sum of all elements in
numbers
- Use a
while
loop (define an index before the loop, use index in thewhile
condition, change the index inside the loop)
Name the program sum.py
. Make sure that gradescope gives you the points for passing the test cases.
Test cases:
Programming Problem 12
Due date: Oct 8, Tuesday at 7pm
Write a Python function that does the following:
- Its name is
concatenate
- It takes a list of strings as argument:
words
- It returns a string with all items in
words
concatenated and separated by spaces - Use a
while
loop (define an index before the loop, use index in thewhile
condition, change the index inside the loop) – the last word in the resulting string is not followed by space
Name the program concatenate.py
. Make sure that gradescope gives you the points for passing the test cases.
Test cases:
def main():
= concatenate([])
value assert value == "", \
f"expected return value was an empty string, but function returned {value}"
= concatenate(["", "", ""])
value assert value == " ", \
f"expected return value was an \" \", but function returned {value}"
= concatenate(["Hi", "there"])
value assert value == "Hi there", \
f"expected return value was an \"Hi There\", but function returned {value}"
print("All tests passed.")
main()