Finals Week Section
Previous Finals Review
Administrivia
2023 Summer Q3 (Style Check)
A student has written the function check_sorted(nums), which checks if a given list is sorted. The function returns True if the list is sorted, and False otherwise.
The input is guaranteed to have at least one element. The student also made some style issues. Please note the four main style issues that the student should fix, and the corresponding change to fix the issue.
Ans key
2015 Spring Q5a (Dictionaries)
Ans key
2018 Spring Q4 (File I/O)
Write a function called remove_words that takes two arguments: the name of a file and a list of undesirable words that should be removed from the contents of that file. Return a single list containing the words from the original file, with all occurrences of the undesirable words removed.
Ans key
23 Spring Q4 (Testing)
Write 3 test cases for the following function that test 3 different cases. Please specify what the cases are testing (as in, why they are different from the other two tests) as well as the value of the input variables. Remember to clearly define the input you will use to call the function!
Ans key
Ans key
23 Summer Q4 (Graph)
Write a function is_connected(graph, vertex1, vertex2) that takes in a graph and two strings representing vertices as input.
The function should return True if vertex1 and vertex2 are connected directly (ex: share an edge), and False otherwise. For example, given the following graph, my_graph, the following function calls would produce the following output
is_connected(my_graph, A, C) �# Returns true since A and C are directly connected �is_connected(my_graph, A, D) �# Returns false since A and D are not directly connected
Ans key