{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyM8O24kw0Ldy885PtPJXehg"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"id":"-6B-O2pMtCS2","executionInfo":{"status":"ok","timestamp":1717697136796,"user_tz":-330,"elapsed":39,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}}},"outputs":[],"source":["# Example 7: Write a Program to calculate the factorial of a number. The number for which factorial is calculated is given by user."]},{"cell_type":"code","source":["# Program to calculate the factorial of a number\n","\n","# take input from the user\n","num = int(input(\"Enter a number: \"))\n","\n","factorial = 1\n","\n","# check if the number is negative, positive or zero\n","if num <0:\n","   print(\"factorial does not exist for negative numbers\")\n","elif num == 0:\n","   print(\"The factorial of 0 is 1\")\n","else:\n","   for i in range(1,num + 1):\n","       factorial = factorial*i\n","   print(\"The factorial of\",num,\"is\",factorial)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"L4OXifkkteb_","executionInfo":{"status":"ok","timestamp":1717697141856,"user_tz":-330,"elapsed":5090,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}},"outputId":"95e46eca-2e5b-47e0-dc5f-30093a2a80dd"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["Enter a number: 6\n","The factorial of 6 is 720\n"]}]},{"cell_type":"code","source":[],"metadata":{"id":"RnLE-oiktefs","executionInfo":{"status":"ok","timestamp":1717697141856,"user_tz":-330,"elapsed":10,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}}},"execution_count":2,"outputs":[]}]}