1 von 12

Finals Week Section

Previous Finals Review

2 von 12

Administrivia

  • HW6 due on Dec. 8th (Tomorrow)
  • Programming and Written Activity due also on Dec. 8th (Tomorrow)
  • Resubmissions closing Dec. 10th (Sunday)
  • Final Exam on Dec. 14th (Thursday) 2:30 PM to 4:20 PM CSE G20 (same classroom as lecture/midterm)

3 von 12

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.

4 von 12

Ans key

5 von 12

2015 Spring Q5a (Dictionaries)

6 von 12

Ans key

7 von 12

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.

8 von 12

Ans key

9 von 12

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!

10 von 12

Ans key

Ans key

11 von 12

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

12 von 12

Ans key