A set of python programming exercises designed for a final exam in computer science. The exercises cover fundamental concepts such as recursion and loops, focusing on practical application of these techniques. Students are challenged to write python functions that perform specific tasks, demonstrating their understanding of core programming principles.
Download Computer Science Final Exam: Python Programming Exercises and more Exams Computer Science in PDF only on Docsity!
Computer Science Final Exam
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): ifn < 10: return n alse: return n % 10 + sum_digits(n // 10) 2, Write a Python function called reverse_list that accepts a list Ist and returns anew list with the clements in reverse order, You must implement the solution using recursion: def reverse_list (Ist): if len (Ist) == return [] alse: return [IstI-1]] + reverse_list (Ist l:-11) 3. Coding Loops Question: Write a Python function called compute_sum that accepts a list of integers Ist and returns the sum of all the clements in the list. You must implement the solution using a loop: del compute_sum (Ist): tatal = 0 for num in Ist: total += num return total