{ "cells": [ { "cell_type": "markdown", "id": "c37acdaf", "metadata": {}, "source": [ "# Assignment 1: Calculate the Factorial\n", " \"Write a function to compute the factorial of a given number n.\n", " The factorial of a number n is the product of all positive integers less than or equal to n.\n", " For example, factorial of 5 is 5 * 4 * 3 * 2 * 1 = 120." ] }, { "cell_type": "code", "execution_count": 1, "id": "ac5b116f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Factorial of 5 is 120\n" ] } ], "source": [ "def factorial(n):\n", " if n == 0 or n == 1:\n", " return 1\n", " else:\n", " return n * factorial(n - 1)\n", " \n", " # Test the function\\,\n", "number = 5\n", "result = factorial(number)\n", "print(f'Factorial of {number} is {result}')" ] }, { "cell_type": "code", "execution_count": null, "id": "80df5cfc", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "ml_env", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 5 }