{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98f86b3a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b6abb283",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "( 3 4 5 )\n",
      "( 5 12 13 )\n",
      "( 6 8 10 )\n",
      "( 7 24 25 )\n",
      "( 8 15 17 )\n",
      "( 9 12 15 )\n",
      "( 9 40 41 )\n",
      "( 10 24 26 )\n",
      "( 11 60 61 )\n",
      "( 12 16 20 )\n",
      "( 12 35 37 )\n",
      "( 13 84 85 )\n",
      "( 14 48 50 )\n",
      "( 15 20 25 )\n",
      "( 15 36 39 )\n",
      "( 16 30 34 )\n",
      "( 16 63 65 )\n",
      "( 18 24 30 )\n",
      "( 18 80 82 )\n",
      "( 20 21 29 )\n",
      "( 20 48 52 )\n",
      "( 21 28 35 )\n",
      "( 21 72 75 )\n",
      "( 24 32 40 )\n",
      "( 24 45 51 )\n",
      "( 24 70 74 )\n",
      "( 25 60 65 )\n",
      "( 27 36 45 )\n",
      "( 28 45 53 )\n",
      "( 28 96 100 )\n",
      "( 30 40 50 )\n",
      "( 30 72 78 )\n",
      "( 32 60 68 )\n",
      "( 33 44 55 )\n",
      "( 33 56 65 )\n",
      "( 35 84 91 )\n",
      "( 36 48 60 )\n",
      "( 36 77 85 )\n",
      "( 39 52 65 )\n",
      "( 39 80 89 )\n",
      "( 40 42 58 )\n",
      "( 40 75 85 )\n",
      "( 42 56 70 )\n",
      "( 45 60 75 )\n",
      "( 48 55 73 )\n",
      "( 48 64 80 )\n",
      "( 51 68 85 )\n",
      "( 54 72 90 )\n",
      "( 57 76 95 )\n",
      "( 60 63 87 )\n",
      "( 60 80 100 )\n",
      "( 65 72 97 )\n"
     ]
    }
   ],
   "source": [
    "def py_triplets(start,end):\n",
    "    \n",
    "    for i in range(start,end+1):\n",
    "        for j in range(i,end+1):\n",
    "            \n",
    "            k_squared = i**2 + j**2\n",
    "            k = int(k_squared**0.5)\n",
    "            \n",
    "            if k**2 == k_squared and k <= end:\n",
    "                print(\"(\",i,j,k,\")\")\n",
    "\n",
    "py_triplets(1,100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ad3ba79",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b4f6ce61",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "234019\n"
     ]
    }
   ],
   "source": [
    "def carry_sum(num):\n",
    "    result = \"\"\n",
    "    for digit in num:\n",
    "        new_digit = (int(digit)+1)%10\n",
    "        result += str(new_digit)\n",
    "    \n",
    "    print(result)\n",
    "\n",
    "carry_sum(\"123908\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "f55eb5ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Digit :1  Binary : 1  Hexadecimal : 1  Octal : 1\n",
      "Digit :2  Binary : 10  Hexadecimal : 2  Octal : 2\n",
      "Digit :3  Binary : 11  Hexadecimal : 3  Octal : 3\n",
      "Digit :4  Binary : 100  Hexadecimal : 4  Octal : 4\n",
      "Digit :5  Binary : 101  Hexadecimal : 5  Octal : 5\n",
      "Digit :6  Binary : 110  Hexadecimal : 6  Octal : 6\n",
      "Digit :7  Binary : 111  Hexadecimal : 7  Octal : 7\n",
      "Digit :8  Binary : 1000  Hexadecimal : 8  Octal : 10\n",
      "Digit :9  Binary : 1001  Hexadecimal : 9  Octal : 11\n",
      "Digit :10  Binary : 1010  Hexadecimal : a  Octal : 12\n",
      "Digit :11  Binary : 1011  Hexadecimal : b  Octal : 13\n",
      "Digit :12  Binary : 1100  Hexadecimal : c  Octal : 14\n",
      "Digit :13  Binary : 1101  Hexadecimal : d  Octal : 15\n",
      "Digit :14  Binary : 1110  Hexadecimal : e  Octal : 16\n",
      "Digit :15  Binary : 1111  Hexadecimal : f  Octal : 17\n",
      "Digit :16  Binary : 10000  Hexadecimal : 10  Octal : 20\n",
      "Digit :17  Binary : 10001  Hexadecimal : 11  Octal : 21\n",
      "Digit :18  Binary : 10010  Hexadecimal : 12  Octal : 22\n",
      "Digit :19  Binary : 10011  Hexadecimal : 13  Octal : 23\n",
      "Digit :20  Binary : 10100  Hexadecimal : 14  Octal : 24\n",
      "Digit :21  Binary : 10101  Hexadecimal : 15  Octal : 25\n",
      "Digit :22  Binary : 10110  Hexadecimal : 16  Octal : 26\n",
      "Digit :23  Binary : 10111  Hexadecimal : 17  Octal : 27\n",
      "Digit :24  Binary : 11000  Hexadecimal : 18  Octal : 30\n",
      "Digit :25  Binary : 11001  Hexadecimal : 19  Octal : 31\n",
      "Digit :26  Binary : 11010  Hexadecimal : 1a  Octal : 32\n",
      "Digit :27  Binary : 11011  Hexadecimal : 1b  Octal : 33\n",
      "Digit :28  Binary : 11100  Hexadecimal : 1c  Octal : 34\n",
      "Digit :29  Binary : 11101  Hexadecimal : 1d  Octal : 35\n",
      "Digit :30  Binary : 11110  Hexadecimal : 1e  Octal : 36\n",
      "Digit :31  Binary : 11111  Hexadecimal : 1f  Octal : 37\n",
      "Digit :32  Binary : 100000  Hexadecimal : 20  Octal : 40\n",
      "Digit :33  Binary : 100001  Hexadecimal : 21  Octal : 41\n",
      "Digit :34  Binary : 100010  Hexadecimal : 22  Octal : 42\n",
      "Digit :35  Binary : 100011  Hexadecimal : 23  Octal : 43\n",
      "Digit :36  Binary : 100100  Hexadecimal : 24  Octal : 44\n",
      "Digit :37  Binary : 100101  Hexadecimal : 25  Octal : 45\n",
      "Digit :38  Binary : 100110  Hexadecimal : 26  Octal : 46\n",
      "Digit :39  Binary : 100111  Hexadecimal : 27  Octal : 47\n",
      "Digit :40  Binary : 101000  Hexadecimal : 28  Octal : 50\n",
      "Digit :41  Binary : 101001  Hexadecimal : 29  Octal : 51\n",
      "Digit :42  Binary : 101010  Hexadecimal : 2a  Octal : 52\n",
      "Digit :43  Binary : 101011  Hexadecimal : 2b  Octal : 53\n",
      "Digit :44  Binary : 101100  Hexadecimal : 2c  Octal : 54\n",
      "Digit :45  Binary : 101101  Hexadecimal : 2d  Octal : 55\n",
      "Digit :46  Binary : 101110  Hexadecimal : 2e  Octal : 56\n",
      "Digit :47  Binary : 101111  Hexadecimal : 2f  Octal : 57\n",
      "Digit :48  Binary : 110000  Hexadecimal : 30  Octal : 60\n",
      "Digit :49  Binary : 110001  Hexadecimal : 31  Octal : 61\n",
      "Digit :50  Binary : 110010  Hexadecimal : 32  Octal : 62\n",
      "Digit :51  Binary : 110011  Hexadecimal : 33  Octal : 63\n",
      "Digit :52  Binary : 110100  Hexadecimal : 34  Octal : 64\n",
      "Digit :53  Binary : 110101  Hexadecimal : 35  Octal : 65\n",
      "Digit :54  Binary : 110110  Hexadecimal : 36  Octal : 66\n",
      "Digit :55  Binary : 110111  Hexadecimal : 37  Octal : 67\n",
      "Digit :56  Binary : 111000  Hexadecimal : 38  Octal : 70\n",
      "Digit :57  Binary : 111001  Hexadecimal : 39  Octal : 71\n",
      "Digit :58  Binary : 111010  Hexadecimal : 3a  Octal : 72\n",
      "Digit :59  Binary : 111011  Hexadecimal : 3b  Octal : 73\n",
      "Digit :60  Binary : 111100  Hexadecimal : 3c  Octal : 74\n",
      "Digit :61  Binary : 111101  Hexadecimal : 3d  Octal : 75\n",
      "Digit :62  Binary : 111110  Hexadecimal : 3e  Octal : 76\n",
      "Digit :63  Binary : 111111  Hexadecimal : 3f  Octal : 77\n",
      "Digit :64  Binary : 1000000  Hexadecimal : 40  Octal : 100\n",
      "Digit :65  Binary : 1000001  Hexadecimal : 41  Octal : 101\n",
      "Digit :66  Binary : 1000010  Hexadecimal : 42  Octal : 102\n",
      "Digit :67  Binary : 1000011  Hexadecimal : 43  Octal : 103\n",
      "Digit :68  Binary : 1000100  Hexadecimal : 44  Octal : 104\n",
      "Digit :69  Binary : 1000101  Hexadecimal : 45  Octal : 105\n",
      "Digit :70  Binary : 1000110  Hexadecimal : 46  Octal : 106\n",
      "Digit :71  Binary : 1000111  Hexadecimal : 47  Octal : 107\n",
      "Digit :72  Binary : 1001000  Hexadecimal : 48  Octal : 110\n",
      "Digit :73  Binary : 1001001  Hexadecimal : 49  Octal : 111\n",
      "Digit :74  Binary : 1001010  Hexadecimal : 4a  Octal : 112\n",
      "Digit :75  Binary : 1001011  Hexadecimal : 4b  Octal : 113\n",
      "Digit :76  Binary : 1001100  Hexadecimal : 4c  Octal : 114\n",
      "Digit :77  Binary : 1001101  Hexadecimal : 4d  Octal : 115\n",
      "Digit :78  Binary : 1001110  Hexadecimal : 4e  Octal : 116\n",
      "Digit :79  Binary : 1001111  Hexadecimal : 4f  Octal : 117\n",
      "Digit :80  Binary : 1010000  Hexadecimal : 50  Octal : 120\n",
      "Digit :81  Binary : 1010001  Hexadecimal : 51  Octal : 121\n",
      "Digit :82  Binary : 1010010  Hexadecimal : 52  Octal : 122\n",
      "Digit :83  Binary : 1010011  Hexadecimal : 53  Octal : 123\n",
      "Digit :84  Binary : 1010100  Hexadecimal : 54  Octal : 124\n",
      "Digit :85  Binary : 1010101  Hexadecimal : 55  Octal : 125\n",
      "Digit :86  Binary : 1010110  Hexadecimal : 56  Octal : 126\n",
      "Digit :87  Binary : 1010111  Hexadecimal : 57  Octal : 127\n",
      "Digit :88  Binary : 1011000  Hexadecimal : 58  Octal : 130\n",
      "Digit :89  Binary : 1011001  Hexadecimal : 59  Octal : 131\n",
      "Digit :90  Binary : 1011010  Hexadecimal : 5a  Octal : 132\n",
      "Digit :91  Binary : 1011011  Hexadecimal : 5b  Octal : 133\n",
      "Digit :92  Binary : 1011100  Hexadecimal : 5c  Octal : 134\n",
      "Digit :93  Binary : 1011101  Hexadecimal : 5d  Octal : 135\n",
      "Digit :94  Binary : 1011110  Hexadecimal : 5e  Octal : 136\n",
      "Digit :95  Binary : 1011111  Hexadecimal : 5f  Octal : 137\n",
      "Digit :96  Binary : 1100000  Hexadecimal : 60  Octal : 140\n",
      "Digit :97  Binary : 1100001  Hexadecimal : 61  Octal : 141\n",
      "Digit :98  Binary : 1100010  Hexadecimal : 62  Octal : 142\n",
      "Digit :99  Binary : 1100011  Hexadecimal : 63  Octal : 143\n",
      "Digit :100  Binary : 1100100  Hexadecimal : 64  Octal : 144\n"
     ]
    }
   ],
   "source": [
    "def print_num(start, end):\n",
    "    for i in range(start, end + 1):\n",
    "        print(f\"Digit :{i:d}  Binary : {i:b}  Hexadecimal : {i:x}  Octal : {i:o}\")\n",
    "\n",
    "print_num(1, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "8771f63b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]\n",
      "129\n"
     ]
    }
   ],
   "source": [
    "# def prime_sum(num):\n",
    "#     prime = []\n",
    "#     if num<2:\n",
    "#         return True\n",
    "#     for i in range(2,int(num**0.5)+1):\n",
    "#         if num % i != 0:\n",
    "#             prime.append(i)\n",
    "#     print(prime)\n",
    "#     print(sum(prime))      \n",
    "    \n",
    "# prime_sum(10)\n",
    "\n",
    "\n",
    "def first_n_primes(n):\n",
    "    primes = []\n",
    "    num = 2\n",
    "    \n",
    "    while len(primes) < n:\n",
    "        is_prime = True\n",
    "        for i in range(2, int(num**0.5) + 1):\n",
    "            if num % i == 0:\n",
    "                is_prime = False\n",
    "                break\n",
    "                \n",
    "        if is_prime:\n",
    "            primes.append(num)     \n",
    "        num += 1\n",
    "        \n",
    "    print(primes)\n",
    "    print(sum(primes))\n",
    "\n",
    "first_n_primes(10)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55c75ab3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c72f30b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter Value : 1\n",
      "Enter Value : 2\n",
      "Enter Value : 3\n",
      "Enter Value : 4\n",
      "Enter Value : 5\n",
      "15.0\n",
      "3.0\n"
     ]
    }
   ],
   "source": [
    "running_total = 0.0\n",
    "\n",
    "def running_num_sum(n):\n",
    "    global running_total \n",
    "    for i in range(n):\n",
    "        values = float(input(\"Enter Value : \"))\n",
    "        running_total+=values\n",
    "    if n > 0:\n",
    "        avg = running_total/n\n",
    "        print(running_total)\n",
    "        print(avg)\n",
    "running_num_sum(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "237e097d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "153\n",
      "370\n",
      "371\n",
      "407\n"
     ]
    }
   ],
   "source": [
    "def armstrong_number(start,end):\n",
    "    for num in range(start,end+1):\n",
    "        str_num = str(num)\n",
    "        order = len(str_num)\n",
    "#         digit_sum = 0\n",
    "#         for digit in str_num:\n",
    "#             digit_sum = int(digit)** order\n",
    "        digit_sum = sum(int(digit) ** order for digit in str_num)\n",
    "        \n",
    "        if num == digit_sum:\n",
    "            print(num)\n",
    "\n",
    "armstrong_number(1,1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32cf3e88",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "6db85df4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "145\n",
      "40585\n"
     ]
    }
   ],
   "source": [
    "# def factorial(num):\n",
    "#     fact = 1\n",
    "#     if num<1:\n",
    "#         return 1\n",
    "#     for i in range(1,num+1):\n",
    "#         fact*=i\n",
    "#     return fact\n",
    "\n",
    "#optional if dont want manually facttorial\n",
    "\n",
    "import math\n",
    "\n",
    "def is_strong(num):\n",
    "    str_num = str(num)\n",
    "    fact_sum =sum(math.factorial(int(d)) for d in str_num)\n",
    "    \n",
    "    return fact_sum == num\n",
    "\n",
    "for i in range(1,100000):\n",
    "    if is_strong(i):\n",
    "        print(i)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "212f1c86",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "**********\n",
      "*        *\n",
      "*        *\n",
      "*        *\n",
      "*        *\n",
      "*        *\n",
      "*        *\n",
      "*        *\n",
      "*        *\n",
      "**********\n"
     ]
    }
   ],
   "source": [
    "def sqrt_pattern(r,c):\n",
    "    for i in range(r,c+1):\n",
    "        for j in range(r,c+1):\n",
    "            if i == r or i == c or j == r or j == c:\n",
    "                print(\"*\",end=\"\")\n",
    "            else:    \n",
    "                print(\" \",end=\"\")\n",
    "        print()\n",
    "\n",
    "sqrt_pattern(1,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "0968c915",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "5\n",
      "7\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "def not_divisible(start,end):\n",
    "    count = 0\n",
    "    for i in range(start,end+1):\n",
    "        if i %2 != 0 and i %3 != 0:\n",
    "            print(i)\n",
    "            count+=1\n",
    "    print(count) \n",
    "\n",
    "not_divisible(1,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bd729395",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*******\n",
      "*******\n",
      "*******\n",
      "***@***\n",
      "*******\n",
      "*******\n",
      "*******\n"
     ]
    }
   ],
   "source": [
    "# def special_pattren(n):\n",
    "#     mid = n // 2 \n",
    "#     for i in range(n):\n",
    "#         if i == mid:\n",
    "#             print(\"**@**\")\n",
    "#         else:\n",
    "#             print(\"*****\")\n",
    "\n",
    "# special_pattren(5)\n",
    "\n",
    "def special_pattern_mxn(m, n):\n",
    "    mid_row = m // 2\n",
    "    mid_col = n // 2\n",
    "    \n",
    "    for i in range(m):\n",
    "        if i == mid_row:\n",
    "            left_stars = \"*\" * mid_col\n",
    "            right_stars = \"*\" * (n - mid_col - 1)\n",
    "            print(left_stars + \"@\" + right_stars)\n",
    "        else:\n",
    "            print(\"*\" * n)\n",
    "\n",
    "special_pattern_mxn(7, 7)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "7087d435",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     1 \n",
      "    1 1 \n",
      "   1 2 1 \n",
      "  1 3 3 1 \n",
      " 1 4 6 4 1 \n"
     ]
    }
   ],
   "source": [
    "def print_pascal_triangle(rows):\n",
    "    for i in range(rows):\n",
    "        print(\" \" * (rows - i), end=\"\")\n",
    "        \n",
    "        val = 1\n",
    "        for j in range(i + 1):\n",
    "            print(val, end=\" \")\n",
    "            val = val * (i - j) // (j + 1)\n",
    "        print()\n",
    "\n",
    "print_pascal_triangle(5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "5879fd62",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.7182818011463847\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "def factorial_reciprocal_sum(n):\n",
    "    series_sum = 0\n",
    "    for i in range(1, n + 1):\n",
    "        series_sum += 1 / math.factorial(i)\n",
    "    print(series_sum)\n",
    "    \n",
    "factorial_reciprocal_sum(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "294a0f37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 x 1 = 1\n",
      "1 x 2 = 2\n",
      "1 x 3 = 3\n",
      "1 x 4 = 4\n",
      "1 x 5 = 5\n",
      "1 x 6 = 6\n",
      "1 x 7 = 7\n",
      "1 x 8 = 8\n",
      "1 x 9 = 9\n",
      "1 x 10 = 10\n",
      "\n",
      "3 x 1 = 3\n",
      "3 x 2 = 6\n",
      "3 x 3 = 9\n",
      "3 x 4 = 12\n",
      "3 x 5 = 15\n",
      "3 x 6 = 18\n",
      "3 x 7 = 21\n",
      "3 x 8 = 24\n",
      "3 x 9 = 27\n",
      "3 x 10 = 30\n",
      "\n",
      "5 x 1 = 5\n",
      "5 x 2 = 10\n",
      "5 x 3 = 15\n",
      "5 x 4 = 20\n",
      "5 x 5 = 25\n",
      "5 x 6 = 30\n",
      "5 x 7 = 35\n",
      "5 x 8 = 40\n",
      "5 x 9 = 45\n",
      "5 x 10 = 50\n",
      "\n",
      "7 x 1 = 7\n",
      "7 x 2 = 14\n",
      "7 x 3 = 21\n",
      "7 x 4 = 28\n",
      "7 x 5 = 35\n",
      "7 x 6 = 42\n",
      "7 x 7 = 49\n",
      "7 x 8 = 56\n",
      "7 x 9 = 63\n",
      "7 x 10 = 70\n",
      "\n",
      "9 x 1 = 9\n",
      "9 x 2 = 18\n",
      "9 x 3 = 27\n",
      "9 x 4 = 36\n",
      "9 x 5 = 45\n",
      "9 x 6 = 54\n",
      "9 x 7 = 63\n",
      "9 x 8 = 72\n",
      "9 x 9 = 81\n",
      "9 x 10 = 90\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def mult_table_odd(start,end):\n",
    "    for num in range(start, end + 1):\n",
    "        if num % 2 != 0:\n",
    "            for i in range(1, 11):\n",
    "                print(f\"{num} x {i} = {num * i}\")\n",
    "            print()\n",
    "                \n",
    "mult_table_odd(1,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "83e831af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         * \n",
      "        * * \n",
      "       * * * \n",
      "      * * * * \n",
      "     * * * * * \n",
      "    * * * * * * \n",
      "   * * * * * * * \n",
      "  * * * * * * * * \n",
      " * * * * * * * * * \n",
      "* * * * * * * * * * \n"
     ]
    }
   ],
   "source": [
    "def print_triangle(rows):\n",
    "    for i in range(1, rows + 1):\n",
    "        print(\" \" * (rows - i) + \"* \" * i)\n",
    "print_triangle(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1c39aa95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     1 \n",
      "    1 1 \n",
      "   1 2 1 \n",
      "  1 3 3 1 \n",
      " 1 4 6 4 1 \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "def print_pascal_triangle(rows):\n",
    "    for i in range(rows):\n",
    "        print(\" \"*(rows-i),end=\"\")\n",
    "        val =1\n",
    "        for j in range(i+1):\n",
    "            val = math.comb(i,j)\n",
    "            print(val,end=\" \")\n",
    "#             val=val*(i-j)//(j+1)\n",
    "            \n",
    "        print()\n",
    "print_pascal_triangle(5)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "700a840c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 11 21 31 41 51 6\n",
      "2 12 22 32 42 52 6\n",
      "3 13 23 33 43 53 6\n",
      "4 14 24 34 44 54 6\n",
      "5 15 25 35 45 55 6\n",
      "6 16 26 36 46 56 6\n"
     ]
    }
   ],
   "source": [
    "def print_square(n):\n",
    "    for i in range(1,n+1):\n",
    "        for j in range(1,n+1):\n",
    "            print(i,j,end=\"\")\n",
    "        print()\n",
    "print_square(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "3a15bb37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 11 21 31 41 5\n",
      "2 22 32 42 5\n",
      "3 33 43 5\n",
      "4 44 5\n",
      "5 5\n"
     ]
    }
   ],
   "source": [
    "def print_triangle(n):\n",
    "    for i in range(1,n+1):\n",
    "        for j in range(i,n+1):\n",
    "            print(i,j,end=\"\")\n",
    "        print()\n",
    "print_triangle(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "5a9c4842",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 11 21 31 41 5\n",
      "2 12 22 32 42 5\n",
      "3 13 23 33 43 5\n",
      "4 14 24 34 44 5\n",
      "5 15 25 35 45 5\n"
     ]
    }
   ],
   "source": [
    "def print_triangle(n):\n",
    "    for i in range(1,n+1):\n",
    "        count = 0\n",
    "        for j in range(1,n+1):\n",
    "            print(i,j,end=\"\")\n",
    "        print()\n",
    "\n",
    "print_triangle(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "73daac10",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         * \n",
      "        * * \n",
      "       * * * \n",
      "      * * * * \n",
      "     * * * * * \n",
      "    * * * * * * \n",
      "   * * * * * * * \n",
      "  * * * * * * * * \n",
      " * * * * * * * * * \n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    print(\" \"*(10-i)+\"* \"*i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "354a3d75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(2,10,1):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bd517e35",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2310'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def carry_sum(n):\n",
    "    r=\"\"\n",
    "    for digit in n:\n",
    "        new_digit = (int(digit)+1)%10\n",
    "        r+=str(new_digit)\n",
    "    return r\n",
    "\n",
    "carry_sum(\"1209\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "818a5460",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]\n",
      "129\n"
     ]
    }
   ],
   "source": [
    "def first_n_prime(n):\n",
    "    prime=[]\n",
    "    num =2\n",
    "    \n",
    "    while len(prime) < n:\n",
    "        is_prime = True\n",
    "        for i in range(2,int(num**0.5)+1):\n",
    "            if num % i == 0:\n",
    "                is_prime = False\n",
    "                break\n",
    "        if is_prime:\n",
    "            prime.append(num)\n",
    "        num+=1\n",
    "    print(prime)\n",
    "    print(sum(prime))\n",
    "        \n",
    "first_n_prime(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "62640612",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "153\n",
      "370\n",
      "371\n",
      "407\n"
     ]
    }
   ],
   "source": [
    "def armstrong_number(start,end):\n",
    "    for num in range(start,end+1):\n",
    "        str_num = str(num)\n",
    "        order = len(str_num)\n",
    "        \n",
    "        digit_sum= sum(int(digit)**order for digit in str_num)\n",
    "        \n",
    "        if num == digit_sum:\n",
    "            print(num)\n",
    "            \n",
    "armstrong_number(1,1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "e448ea91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         * \n",
      "        * * \n",
      "       * * * \n",
      "      * * * * \n",
      "     * * * * * \n",
      "    * * * * * * \n",
      "   * * * * * * * \n",
      "  * * * * * * * * \n",
      " * * * * * * * * * \n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    print(\" \"*(10-i)+\"* \"*i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "136bbae3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6661b36",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
