From 7549c96264798a06a098b1622c5322300357e7e3 Mon Sep 17 00:00:00 2001 From: Yugenjr Date: Sat, 28 Sep 2024 15:48:00 +0530 Subject: [PATCH 1/2] Create README.md readme added --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..af4c453 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +says hello by using html From 00c3f7ce9d8c6e858a9fc142ceefce1bc0633252 Mon Sep 17 00:00:00 2001 From: Yugenjr Date: Tue, 25 Feb 2025 19:36:18 +0530 Subject: [PATCH 2/2] Created using Colab --- pythonproject1.ipynb | 1164 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1164 insertions(+) create mode 100644 pythonproject1.ipynb diff --git a/pythonproject1.ipynb b/pythonproject1.ipynb new file mode 100644 index 0000000..8d2fff4 --- /dev/null +++ b/pythonproject1.ipynb @@ -0,0 +1,1164 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyNZJwS6L2/Xe/7Qfzkpz1y/", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "source": [ + "Homework 1\n" + ], + "metadata": { + "id": "aa677HpiKtzh" + } + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "VXQyZlVkJB7t", + "outputId": "b121cdc7-3193-44ef-9e24-e0e0aa04615a" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "1 2 3\n" + ] + } + ], + "source": [ + "a, b, c = 1, 2, 3\n", + "print(a, b, c)\n", + "# assign elements in single line" + ] + }, + { + "cell_type": "code", + "source": [ + "celsius = int(input(\"Enter degrees in Celsius: \"))\n", + "fahrenheit = (celsius * 9/5) + 32\n", + "print(fahrenheit)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "pEi0_pRyJrqe", + "outputId": "8239be21-5662-4c35-ef71-302fc25b1da7" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter degrees in Celsius: 45\n", + "113.0\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import keyword\n", + "\n", + "word = input(\"enter keywrd\")\n", + "print(keyword.iskeyword(word))\n", + "#keywords" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "DFLk0JFVJvOV", + "outputId": "f3918a73-ceba-43d3-b274-9959eb22b0d9" + }, + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "enter keywrdtrue\n", + "False\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def factorial(n):\n", + " if n == 0:\n", + " return 1\n", + " else:\n", + " return n * factorial(n-1)\n", + "\n", + "number=int(input(\"enter number\"))\n", + "print(factorial(number))\n", + "#factorials" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "KXUxvGDIJyBn", + "outputId": "485b6af4-9e06-4910-f688-f615c031f596" + }, + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "enter number7\n", + "5040\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "number = int(input(\"enter num\"))\n", + "last_digit = number % 10\n", + "print(last_digit)\n", + "#last digit" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "YJsQ5kD8J4Ta", + "outputId": "d0041134-15ad-4d9c-e8a6-1ae63f90f75e" + }, + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "enter num4\n", + "4\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "a = int(input(\"enter a\"))\n", + "b = int(input(\"enter b\"))\n", + "maximum = a if a > b else b\n", + "print(maximum)\n", + "#max check" + ], + "metadata": { + "id": "XH8oA0HfJ_DH" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def is_leap_year(year):\n", + " return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)\n", + "\n", + "year = 2024\n", + "print(is_leap_year(year))\n", + "#leap year check" + ], + "metadata": { + "id": "03FtL4izKCFP" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def is_prime(n):\n", + " if n <= 1:\n", + " return False\n", + "\n", + " for i in range(2, int(n**0.5) + 1):\n", + " if n % i == 0:\n", + " return False\n", + " return True\n", + "\n", + "number = int(input(\"Enter a number: \"))\n", + "print(is_prime(number))\n", + "#checks prime" + ], + "metadata": { + "id": "ff3jL6oIKEm_" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "num = int(input(\"Enter a number: \"))\n", + "print(sum(map(int, str(num))))\n", + "\n", + "# summed the digits" + ], + "metadata": { + "id": "weR1toqBKL6v" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "a=5\n", + "b=2\n", + "a=a-b\n", + "b=a+b\n", + "a=b-a\n", + "print(a , b)\n", + "# swapped" + ], + "metadata": { + "id": "6_RSCXTDKP2a" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "homework 2" + ], + "metadata": { + "id": "nqpZDx7kKevq" + } + }, + { + "cell_type": "code", + "source": [ + "multi_lines = \"\"\"This is a multi-line string.\n", + "It gives us multiple lines.\n", + "Python supports it using triple quotes.\"\"\"\n", + "print(multi_lines)" + ], + "metadata": { + "id": "Vd92EyPaKqqJ" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "binary_numb = 0b1010\n", + "octal_numb = 0o12\n", + "hex_numb = 0xA\n", + "\n", + "print(\"Binary:\", binary_numb)\n", + "print(\"Octal:\", octal_numb)\n", + "print(\"Hexadecimal:\", hex_numb)" + ], + "metadata": { + "id": "Fdp8RJuKK-Xb" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "print(True + True + False) # 1 + 1 + 0 = 2\n", + "print(False - True) # 0 - 1 = -1\n", + "print(True * 5) # 1 * 5 = 5" + ], + "metadata": { + "id": "A83QZQ66LFeQ" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "string1 = \"Hello\"\n", + "string2 = \"World\"\n", + "result = string1 + \" \" + string2\n", + "print(result)" + ], + "metadata": { + "id": "THuXelpILJSN" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "int_numb = 10\n", + "float_numb = 20.5\n", + "complex_numb = 3 + 4j\n", + "\n", + "print(\"Integer:\", int_numb)\n", + "print(\"Float:\", float_numb)\n", + "print(\"Complex:\", complex_numb)" + ], + "metadata": { + "id": "a_M7L2D1LMyU" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "numb = 5\n", + "is_positive = numb > 0\n", + "print(\"Is the number positive?\", is_positive)" + ], + "metadata": { + "id": "rtZba9DlLN_u" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var = None\n", + "print(\"Variable type:\", type(var))" + ], + "metadata": { + "id": "rFHv1bcnLSqB" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "fruits = [\"Apple\", \"Banana\", \"Cherry\"]\n", + "numbers_tuple = (10, 20, 30)\n", + "key_value_dict = {\"name\": \"Alice\", \"age\": 25}\n", + "colors_set = {\"Red\", \"Green\", \"Blue\"}\n", + "\n", + "print(\"List:\", fruits)\n", + "print(\"Tuple:\", numbers_tuple)\n", + "print(\"Dictionary:\", key_value_dict)\n", + "print(\"Set:\", colors_set)\n" + ], + "metadata": { + "id": "zYQQyNCLLVQ9" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "a = 10 # Integer\n", + "b = 5.5 # Float\n", + "\n", + "print(\"Addition:\", a + b)\n", + "print(\"Subtraction:\", a - b)\n", + "print(\"Multiplication:\", a * b)\n", + "print(\"Division:\", a / b)\n" + ], + "metadata": { + "id": "OwqK_oF0LWkY" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "my_set = {1, 2, 3}\n", + "my_set.add(4) # Adding an element\n", + "my_set.remove(2) # Removing an existing element\n", + "print(\"Updated Set:\", my_set)" + ], + "metadata": { + "id": "I8_1qpe8LZez" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Conditional and iterative statements" + ], + "metadata": { + "id": "1wN4fkCtLd4X" + } + }, + { + "cell_type": "code", + "source": [ + "for i in range(1500,2701):\n", + " if(i%7==0 and i%5==0):\n", + " print(i)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "FeUBN-tjLy_c", + "outputId": "ec692ed3-147a-4cec-d43c-59e1b707c8f5" + }, + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "1505\n", + "1540\n", + "1575\n", + "1610\n", + "1645\n", + "1680\n", + "1715\n", + "1750\n", + "1785\n", + "1820\n", + "1855\n", + "1890\n", + "1925\n", + "1960\n", + "1995\n", + "2030\n", + "2065\n", + "2100\n", + "2135\n", + "2170\n", + "2205\n", + "2240\n", + "2275\n", + "2310\n", + "2345\n", + "2380\n", + "2415\n", + "2450\n", + "2485\n", + "2520\n", + "2555\n", + "2590\n", + "2625\n", + "2660\n", + "2695\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "# prompt: construct pattern\n", + "# *\n", + "# * *\n", + "# * * *\n", + "# * *\n", + "# *\n", + "\n", + "rows = int(input(\"Enter rows\"))\n", + "for i in range(1, rows + 1):\n", + " if i <= 3:\n", + " print(\"* \" * i)\n", + " else:\n", + " print(\"* \" * (rows - i +1))\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "-U28pa-vMIbS", + "outputId": "6e038ced-c048-4279-aea8-ced497c18462" + }, + "execution_count": 10, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter rows6\n", + "* \n", + "* * \n", + "* * * \n", + "* * * \n", + "* * \n", + "* \n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "word = input(\"Input a word to reverse: \")\n", + "for char in reversed(word):\n", + " print(char, end=\"\")\n", + "print(\"\")\n" + ], + "metadata": { + "id": "DSWkeLRaNOxZ" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def count_even_odd(numbers):\n", + " even_count = 0\n", + " odd_count = 0\n", + " for number in numbers:\n", + " if number % 2 == 0:\n", + " even_count += 1\n", + " else:\n", + " odd_count += 1\n", + " return even_count, odd_count\n", + "\n", + "numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)\n", + "even, odd = count_even_odd(numbers)\n", + "print(\"Number of even numbers :\", even)\n", + "print(\"Number of odd numbers :\", odd)" + ], + "metadata": { + "id": "EShsdrJVNm_-" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "for i in range (0,7):\n", + " if i==3:\n", + " continue\n", + " if i==6:\n", + " continue\n", + " print(i)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "QgByoE7GNomK", + "outputId": "f38dc53e-3159-4a6d-b0b4-3683419a0949" + }, + "execution_count": 18, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0\n", + "1\n", + "2\n", + "4\n", + "5\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def fibonacci_series(limit):\n", + " if limit <= 0:\n", + " return\n", + " a, b = 0, 1\n", + " while a <= limit:\n", + " if a > 0:\n", + " print(a, end=\" \")\n", + " a, b = b, a + b\n", + "fibonacci_series(50)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "SdE7zyRpN3oM", + "outputId": "86ad063a-d87c-4fed-ebb9-94d2758fee44" + }, + "execution_count": 22, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "1 1 2 3 5 8 13 21 34 " + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "for i in range (0,51):\n", + " if(i%3==0 and i%5==0):\n", + " print(\"FizzBuzz\")\n", + " elif(i%3==0):\n", + " print(\"Fizz\")\n", + " elif(i%5==0):\n", + " print(\"Buzz\")\n", + " else:\n", + " print(i)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "Pd9YFXLTPH9G", + "outputId": "212f366b-bd88-4e5c-a312-2676b0700a1f" + }, + "execution_count": 24, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "FizzBuzz\n", + "1\n", + "2\n", + "Fizz\n", + "4\n", + "Buzz\n", + "Fizz\n", + "7\n", + "8\n", + "Fizz\n", + "Buzz\n", + "11\n", + "Fizz\n", + "13\n", + "14\n", + "FizzBuzz\n", + "16\n", + "17\n", + "Fizz\n", + "19\n", + "Buzz\n", + "Fizz\n", + "22\n", + "23\n", + "Fizz\n", + "Buzz\n", + "26\n", + "Fizz\n", + "28\n", + "29\n", + "FizzBuzz\n", + "31\n", + "32\n", + "Fizz\n", + "34\n", + "Buzz\n", + "Fizz\n", + "37\n", + "38\n", + "Fizz\n", + "Buzz\n", + "41\n", + "Fizz\n", + "43\n", + "44\n", + "FizzBuzz\n", + "46\n", + "47\n", + "Fizz\n", + "49\n", + "Buzz\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def process_lines():\n", + " lines = []\n", + " while True:\n", + " line = input()\n", + " if not line:\n", + " break\n", + " lines.append(line.lower())\n", + " for line in lines:\n", + " print(line)\n", + "\n", + "process_lines()\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "KxDaoW-TQJba", + "outputId": "ef9b86fd-4c44-4d1f-bb84-3658a042588b" + }, + "execution_count": 25, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ggfhgjhjhgk\n", + "jhgiugkb\n", + "jhhjhvhjj\n", + "\n", + "ggfhgjhjhgk\n", + "jhgiugkb\n", + "jhhjhvhjj\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "l = input(\"Input a letter of the alphabet: \")\n", + "if l in ('a', 'e', 'i', 'o', 'u'):\n", + " print(l, \"is a vowel.\")\n", + "else:\n", + " print(l, \"is a consonant.\")\n" + ], + "metadata": { + "id": "iNyZtmOQQkMa" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "a=int(input(\"enter a \"))\n", + "b=int(input(\"enter b \"))\n", + "sum=a+b\n", + "if 20>=sum>=15:\n", + " print(\"20\")\n", + "else:\n", + " print(sum)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "gUaMhZQWRP2m", + "outputId": "a41a63e5-185c-4a5f-c7fa-068a93f2975a" + }, + "execution_count": 28, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "enter a 44\n", + "enter b 4\n", + "48\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "a=int(input(\"enter side 1 \"))\n", + "b=int(input(\"enter side 2 \"))\n", + "c=int(input(\"enter side 3 \"))\n", + "if a==b==c:\n", + " print(\"equilateral triangle\")\n", + "elif a==b or b==c or c==a:\n", + " print(\"isosceles triangle\")\n", + "else:\n", + " print(\"scalene triangle\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "mTdbj4PaSHHK", + "outputId": "62dc1403-d8a0-4ee7-feea-fe2820eab75f" + }, + "execution_count": 29, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "enter side 15\n", + "enter side 29\n", + "enter side 39\n", + "isosceles triangle\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "a=int(input(\"enter a number\"))\n", + "i=1\n", + "for i in range (1,11):\n", + " print(a,\"x\",i,\"=\",i*a)\n", + " i+1\n", + "" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "gCYpLkKZSfVf", + "outputId": "691d482d-53da-4c69-b44e-cef34c1c9227" + }, + "execution_count": 30, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "enter a number6\n", + "6 x 1 = 6\n", + "6 x 2 = 12\n", + "6 x 3 = 18\n", + "6 x 4 = 24\n", + "6 x 5 = 30\n", + "6 x 6 = 36\n", + "6 x 7 = 42\n", + "6 x 8 = 48\n", + "6 x 9 = 54\n", + "6 x 10 = 60\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "a=1\n", + "while(a!=10):\n", + " print(a)\n", + " a+=1" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "_bLGB5JET2jN", + "outputId": "4a680e0c-03c6-401a-d2fb-83af7a4cbd2d" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "a=int(input(\"Enter a number\"))\n", + "print((a*(a+1))/2)" + ], + "metadata": { + "collapsed": true, + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "XZQNVE-EVKyu", + "outputId": "7900b1d8-0218-4fb0-8203-4ac0a7fac60d" + }, + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter a number23\n", + "276.0\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def count_digits(number):\n", + " num_str = str(number)\n", + " return len(num_str)\n", + "number = int(input(\"enter number\"))\n", + "print(f\"The total number of digits in {number} is {count_digits(number)}\")\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "uhpecmgbVekb", + "outputId": "eec4f440-2681-40dd-9d69-fd997e1d13ec" + }, + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "enter number564\n", + "The total number of digits in 564 is 3\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "for i in range(-10, 0):\n", + " print(i)\n", + "else:\n", + " print(\"Done\")" + ], + "metadata": { + "id": "zUCJAyq4aFIF" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def is_prime(n):\n", + "\n", + " if n <= 1:\n", + " return False\n", + " for i in range(2, n):\n", + " if n % i == 0:\n", + " return False\n", + " return True\n", + "\n", + "start = int(input(\"Enter the starting number: \"))\n", + "end = int(input(\"Enter the ending number: \"))\n", + "for num in range(start, end + 1):\n", + " if is_prime(num):\n", + " print(num)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "VTPg8HOkaM_z", + "outputId": "d7f6b6d1-f9ba-42dd-9a24-cb38af1ddb83" + }, + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter the starting number: 1\n", + "Enter the ending number: 90\n", + "2\n", + "3\n", + "5\n", + "7\n", + "11\n", + "13\n", + "17\n", + "19\n", + "23\n", + "29\n", + "31\n", + "37\n", + "41\n", + "43\n", + "47\n", + "53\n", + "59\n", + "61\n", + "67\n", + "71\n", + "73\n", + "79\n", + "83\n", + "89\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def fibonacci_series(n):\n", + " if n <= 0:\n", + " print(\"Please enter a positive integer.\")\n", + " elif n == 1:\n", + " print(\"0\")\n", + " else:\n", + " a, b = 0, 1\n", + " print(\"Fibonacci Series:\")\n", + " for _ in range(n):\n", + " print(a, end=\" \")\n", + " a, b = b, a + b\n", + "fibonacci_series(10)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "0VsG9hhPa-gM", + "outputId": "c8a27940-95d6-4622-c6a3-4c6d8b0ea087" + }, + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Fibonacci Series:\n", + "0 1 1 2 3 5 8 13 21 34 " + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "def factorial(n):\n", + " if n == 0:\n", + " return 1\n", + " else:\n", + " return n * factorial(n - 1)\n", + "\n", + "# Example usage\n", + "number = int(input(\"Enter a number: \"))\n", + "print(f\"The factorial of {number} is {factorial(number)}\")" + ], + "metadata": { + "id": "RJ4ErJKKbRXO" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def reverse_integer(number):\n", + " reversed_number = 0\n", + " while number != 0:\n", + " digit = number % 10\n", + " reversed_number = reversed_number * 10 + digit\n", + " number //= 10\n", + " return reversed_number\n", + "\n", + "# Example usage:\n", + "number = 12345\n", + "reversed_number = reverse_integer(number)\n", + "print(\"Reversed Number:\", reversed_number)" + ], + "metadata": { + "id": "q19y393mbZ8q" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def cube_numbers(n):\n", + " cubes = {i: i**3 for i in range(1, n + 1)}\n", + " return cubes\n", + "\n", + "# Example usage:\n", + "given_number = 5\n", + "cubes = cube_numbers(given_number)\n", + "for number, cube in cubes.items():\n", + " print(f\"The cube of {number} is {cube}\")" + ], + "metadata": { + "id": "y1UMPFdUbiF4" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def calculate_sum_and_average():\n", + " total_sum = 0\n", + " count = 0\n", + "\n", + " while True:\n", + " user_input = int(input(\"Enter an integer (0 to finish): \"))\n", + " if user_input == 0:\n", + " break\n", + " total_sum += user_input\n", + " count += 1\n", + "\n", + " if count > 0:\n", + " average = total_sum / count\n", + " print(f\"Sum of entered numbers: {total_sum}\")\n", + " print(f\"Average of entered numbers: {average}\")\n", + " else:\n", + " print(\"No numbers were entered.\")\n", + "calculate_sum_and_average()\n" + ], + "metadata": { + "id": "DYfGid9jcGft" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file