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
Escuela, estudio y materia
- Institución
- Computer Science
- Grado
- Computer Science
Información del documento
- Subido en
- 5 de marzo de 2025
- Número de páginas
- 4
- Escrito en
- 2024/2025
- Tipo
- Examen
- Contiene
- Preguntas y respuestas
Temas
-
computer science
-
computer science final exam 2025