Computer Science Final Exam 2025
Computer Science Final Exam 2025 1. Write a Python function called sum_digits that accepts an integer n and returns the sum of its digits. You must implement the solution using recur sion: def sum_digits(n): if n < 10: return n else: return n % 10 + sum_digits(n // 10) 2. Write a Python function called reverse_list that accepts a list lst and returns a new list with the elements in reverse order. You must implement the solution using recursion: def reverse_list(lst): if len(lst) == 0: return [ ] else: return [lst[-1]] + reverse_list(lst[:-1]) 3. Coding Loops Question: Write a Python function called compute_sum that accepts a list of integers lst and returns the sum of all the elements in the list. You must implement the solution using a loop: def compute_sum(lst): total = 0
Written for
- Institution
- Computer Science
- Course
- Computer Science
Document information
- Uploaded on
- March 5, 2025
- Number of pages
- 4
- Written in
- 2024/2025
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
- computer science
-
computer science final exam 2025