Skip to main content
Practice

coding-quiz-2

---
id: coding-quiz-2
title: Coding Quiz - Calculating the Sum of a List Recursively
description: Write a function to calculate the sum of all elements in a list recursively.
tags:
- Coding Quiz
- Recursive Function
- Python
- Practice
sidebar_position: 3
isPublic: false
---

# Coding Quiz - Calculating the Sum of a List Recursively

In this coding quiz, you'll write a function that `calculates the sum of all elements in a given list recursively`.

You will receive a list containing multiple integers from the user and create a program that `calculates and outputs the sum` of all the elements in the list using a `recursive method`.

<br />

```python title="Write Code"
def solution(numbers):
# Write your code here
return



Constraints

  • The input should be a list containing integers.

  • The list may be empty or contain one or more integers.

  • Each integer in the list can be positive or negative.




Example Input/Output

  • Input: [1, 2, 3, 4, 5]

  • Output: 15


  • Input: [-1, -2, -3, -4, -5]

  • Output: -15

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.