{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "24\n" ] } ], "source": [ "# Write a Python program to calculate the sum of a list of numbers. (in recursion fashion)\n", "\n", "def list_sum(num_List):\n", " if len(num_List) == 1:\n", " return num_List[0]\n", " else:\n", " return num_List[0] + list_sum(num_List[1:])\n", " \n", "print(list_sum([2, 4, 5, 6, 7]))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }