SHARE
TWEET

Untitled

a guest Jun 16th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "markdown",
  5.    "metadata": {},
  6.    "source": [
  7.     "# This is Markdown"
  8.    ]
  9.   },
  10.   {
  11.    "cell_type": "code",
  12.    "execution_count": 2,
  13.    "metadata": {},
  14.    "outputs": [],
  15.    "source": [
  16.     "# This is code"
  17.    ]
  18.   },
  19.   {
  20.    "cell_type": "code",
  21.    "execution_count": 3,
  22.    "metadata": {},
  23.    "outputs": [
  24.     {
  25.      "name": "stdout",
  26.      "output_type": "stream",
  27.      "text": [
  28.       "hello universe!\n"
  29.      ]
  30.     }
  31.    ],
  32.    "source": [
  33.     "print (\"hello universe!\")"
  34.    ]
  35.   },
  36.   {
  37.    "cell_type": "markdown",
  38.    "metadata": {},
  39.    "source": [
  40.     "## Print Statement"
  41.    ]
  42.   },
  43.   {
  44.    "cell_type": "code",
  45.    "execution_count": 4,
  46.    "metadata": {},
  47.    "outputs": [
  48.     {
  49.      "name": "stdout",
  50.      "output_type": "stream",
  51.      "text": [
  52.       "type of 5 is <class 'str'>\n"
  53.      ]
  54.     }
  55.    ],
  56.    "source": [
  57.     "A='5'\n",
  58.     "print('type of',A,'is',type(A))"
  59.    ]
  60.   },
  61.   {
  62.    "cell_type": "markdown",
  63.    "metadata": {},
  64.    "source": [
  65.     "## Data types"
  66.    ]
  67.   },
  68.   {
  69.    "cell_type": "code",
  70.    "execution_count": 5,
  71.    "metadata": {},
  72.    "outputs": [
  73.     {
  74.      "name": "stdout",
  75.      "output_type": "stream",
  76.      "text": [
  77.       "type of 5 is <class 'int'>\n"
  78.      ]
  79.     }
  80.    ],
  81.    "source": [
  82.     "A=5\n",
  83.     "print('type of',A,'is',type(A))"
  84.    ]
  85.   },
  86.   {
  87.    "cell_type": "code",
  88.    "execution_count": 6,
  89.    "metadata": {},
  90.    "outputs": [
  91.     {
  92.      "name": "stdout",
  93.      "output_type": "stream",
  94.      "text": [
  95.       "type of 5.0 is <class 'float'>\n"
  96.      ]
  97.     }
  98.    ],
  99.    "source": [
  100.     "A=5.0\n",
  101.     "print('type of',A,'is',type(A))"
  102.    ]
  103.   },
  104.   {
  105.    "cell_type": "code",
  106.    "execution_count": 7,
  107.    "metadata": {},
  108.    "outputs": [
  109.     {
  110.      "name": "stdout",
  111.      "output_type": "stream",
  112.      "text": [
  113.       "type of True is <class 'bool'>\n"
  114.      ]
  115.     }
  116.    ],
  117.    "source": [
  118.     "A=True\n",
  119.     "print('type of',A,'is',type(A))"
  120.    ]
  121.   },
  122.   {
  123.    "cell_type": "code",
  124.    "execution_count": 8,
  125.    "metadata": {},
  126.    "outputs": [
  127.     {
  128.      "name": "stdout",
  129.      "output_type": "stream",
  130.      "text": [
  131.       "type of (100+2j) is <class 'complex'>\n"
  132.      ]
  133.     }
  134.    ],
  135.    "source": [
  136.     "A=100+2j\n",
  137.     "print('type of',A,'is',type(A))"
  138.    ]
  139.   },
  140.   {
  141.    "cell_type": "code",
  142.    "execution_count": null,
  143.    "metadata": {},
  144.    "outputs": [],
  145.    "source": []
  146.   },
  147.   {
  148.    "cell_type": "code",
  149.    "execution_count": 9,
  150.    "metadata": {},
  151.    "outputs": [
  152.     {
  153.      "name": "stdout",
  154.      "output_type": "stream",
  155.      "text": [
  156.       "type of [1, 2, 3, 4, 5] is <class 'list'>\n",
  157.       "type of 2 is <class 'int'>\n"
  158.      ]
  159.     }
  160.    ],
  161.    "source": [
  162.     "A=[1,2,3,4,5]\n",
  163.     "print('type of',A,'is',type(A))\n",
  164.     "print('type of',A[1],'is',type(A[1]))"
  165.    ]
  166.   },
  167.   {
  168.    "cell_type": "code",
  169.    "execution_count": 10,
  170.    "metadata": {},
  171.    "outputs": [
  172.     {
  173.      "name": "stdout",
  174.      "output_type": "stream",
  175.      "text": [
  176.       "type of {1: 'orange', 2: 'apple', 3: 'mango', 4: 'banana'} is <class 'dict'>\n",
  177.       "type of orange is <class 'str'>\n"
  178.      ]
  179.     }
  180.    ],
  181.    "source": [
  182.     "Dict={1:'orange',2:'apple',3:'mango',4:'banana'}\n",
  183.     "print('type of',Dict,'is',type(Dict))\n",
  184.     "print('type of',Dict[1],'is',type(Dict[1]))"
  185.    ]
  186.   },
  187.   {
  188.    "cell_type": "code",
  189.    "execution_count": 11,
  190.    "metadata": {},
  191.    "outputs": [
  192.     {
  193.      "name": "stdout",
  194.      "output_type": "stream",
  195.      "text": [
  196.       "type of (1, 2, 3, 4) is <class 'tuple'>\n",
  197.       "type of 2 is <class 'int'>\n"
  198.      ]
  199.     }
  200.    ],
  201.    "source": [
  202.     "Tup=(1,2,3,4)\n",
  203.     "print('type of',Tup,'is',type(Tup))\n",
  204.     "print('type of',Tup[1],'is',type(Tup[1]))"
  205.    ]
  206.   },
  207.   {
  208.    "cell_type": "markdown",
  209.    "metadata": {},
  210.    "source": [
  211.     "## List Operations"
  212.    ]
  213.   },
  214.   {
  215.    "cell_type": "code",
  216.    "execution_count": 12,
  217.    "metadata": {},
  218.    "outputs": [
  219.     {
  220.      "name": "stdout",
  221.      "output_type": "stream",
  222.      "text": [
  223.       "[1, 77, 3, 4, 5]\n"
  224.      ]
  225.     }
  226.    ],
  227.    "source": [
  228.     "#Update list value\n",
  229.     "A[1]=77\n",
  230.     "print(A)"
  231.    ]
  232.   },
  233.   {
  234.    "cell_type": "code",
  235.    "execution_count": 13,
  236.    "metadata": {},
  237.    "outputs": [
  238.     {
  239.      "name": "stdout",
  240.      "output_type": "stream",
  241.      "text": [
  242.       "[1, 77, 3, 5]\n"
  243.      ]
  244.     }
  245.    ],
  246.    "source": [
  247.     "# delete list elements\n",
  248.     "\n",
  249.     "del A[3]\n",
  250.     "print(A)"
  251.    ]
  252.   },
  253.   {
  254.    "cell_type": "code",
  255.    "execution_count": 14,
  256.    "metadata": {},
  257.    "outputs": [
  258.     {
  259.      "name": "stdout",
  260.      "output_type": "stream",
  261.      "text": [
  262.       "[1, 77]\n"
  263.      ]
  264.     }
  265.    ],
  266.    "source": [
  267.     "# to print upto first 2 elements. Here, the 0, 1 position elements are printed.\n",
  268.     "print(A[0:2])"
  269.    ]
  270.   },
  271.   {
  272.    "cell_type": "code",
  273.    "execution_count": 15,
  274.    "metadata": {},
  275.    "outputs": [
  276.     {
  277.      "name": "stdout",
  278.      "output_type": "stream",
  279.      "text": [
  280.       "[77, 3, 5]\n"
  281.      ]
  282.     }
  283.    ],
  284.    "source": [
  285.     "# Here starting from position 1 remaining elements are printed.\n",
  286.     "print(A[1:])"
  287.    ]
  288.   },
  289.   {
  290.    "cell_type": "code",
  291.    "execution_count": 16,
  292.    "metadata": {},
  293.    "outputs": [
  294.     {
  295.      "name": "stdout",
  296.      "output_type": "stream",
  297.      "text": [
  298.       "[1, 77, 3]\n"
  299.      ]
  300.     }
  301.    ],
  302.    "source": [
  303.     "#Here upto 2nd index elements are printed. \n",
  304.     "print(A[:3])"
  305.    ]
  306.   },
  307.   {
  308.    "cell_type": "code",
  309.    "execution_count": 17,
  310.    "metadata": {},
  311.    "outputs": [
  312.     {
  313.      "name": "stdout",
  314.      "output_type": "stream",
  315.      "text": [
  316.       "[1, 77, 3, 5]\n"
  317.      ]
  318.     }
  319.    ],
  320.    "source": [
  321.     "# All the elements are printed it is equal to print(A) but more understandable that we are going to print a list.\n",
  322.     "print(A[:])"
  323.    ]
  324.   },
  325.   {
  326.    "cell_type": "code",
  327.    "execution_count": 18,
  328.    "metadata": {},
  329.    "outputs": [
  330.     {
  331.      "name": "stdout",
  332.      "output_type": "stream",
  333.      "text": [
  334.       "['Thor', 'ironman', 'Captain America', 'Hulk', 'Ant man', 'Captain Marvel']\n"
  335.      ]
  336.     }
  337.    ],
  338.    "source": [
  339.     "# Addition of lists\n",
  340.     "A=['Thor', 'ironman', 'Captain America', 'Hulk']\n",
  341.     "B=['Ant man','Captain Marvel']\n",
  342.     "C = A + B\n",
  343.     "\n",
  344.     "print (C)"
  345.    ]
  346.   },
  347.   {
  348.    "cell_type": "code",
  349.    "execution_count": 27,
  350.    "metadata": {},
  351.    "outputs": [
  352.     {
  353.      "name": "stdout",
  354.      "output_type": "stream",
  355.      "text": [
  356.       "[1, 2, 2, 1, 2, 2]\n"
  357.      ]
  358.     }
  359.    ],
  360.    "source": [
  361.     "# Multiplication of lists\n",
  362.     "\n",
  363.     "A = [1,2,2]\n",
  364.     "\n",
  365.     "B = A*2\n",
  366.     "\n",
  367.     "print(B)"
  368.    ]
  369.   },
  370.   {
  371.    "cell_type": "code",
  372.    "execution_count": null,
  373.    "metadata": {},
  374.    "outputs": [],
  375.    "source": []
  376.   },
  377.   {
  378.    "cell_type": "code",
  379.    "execution_count": 28,
  380.    "metadata": {},
  381.    "outputs": [
  382.     {
  383.      "name": "stdout",
  384.      "output_type": "stream",
  385.      "text": [
  386.       "minimum is 1\n",
  387.       "maximum is 2\n",
  388.       "length is 6\n"
  389.      ]
  390.     }
  391.    ],
  392.    "source": [
  393.     "# List functions\n",
  394.     "\n",
  395.     "print('minimum is',min(B))\n",
  396.     "print('maximum is',max(B))\n",
  397.     "print('length is',len(B))"
  398.    ]
  399.   },
  400.   {
  401.    "cell_type": "code",
  402.    "execution_count": 29,
  403.    "metadata": {},
  404.    "outputs": [
  405.     {
  406.      "name": "stdout",
  407.      "output_type": "stream",
  408.      "text": [
  409.       "after appending [1, 2, 2, 1, 2, 2, ['a', 'b']]\n"
  410.      ]
  411.     }
  412.    ],
  413.    "source": [
  414.     "B.append(['a','b'])\n",
  415.     "print('after appending',B)"
  416.    ]
  417.   },
  418.   {
  419.    "cell_type": "code",
  420.    "execution_count": 30,
  421.    "metadata": {},
  422.    "outputs": [
  423.     {
  424.      "name": "stdout",
  425.      "output_type": "stream",
  426.      "text": [
  427.       "after extending [1, 2, 2, 1, 2, 2, ['a', 'b'], 'b', 'a', 'c']\n"
  428.      ]
  429.     }
  430.    ],
  431.    "source": [
  432.     "B.extend(['b','a','c'])\n",
  433.     "print('after extending',B)"
  434.    ]
  435.   },
  436.   {
  437.    "cell_type": "code",
  438.    "execution_count": 31,
  439.    "metadata": {},
  440.    "outputs": [
  441.     {
  442.      "name": "stdout",
  443.      "output_type": "stream",
  444.      "text": [
  445.       "count of 2 in B list 4\n"
  446.      ]
  447.     }
  448.    ],
  449.    "source": [
  450.     "print('count of 2 in B list',B.count(2))"
  451.    ]
  452.   },
  453.   {
  454.    "cell_type": "code",
  455.    "execution_count": 33,
  456.    "metadata": {},
  457.    "outputs": [
  458.     {
  459.      "name": "stdout",
  460.      "output_type": "stream",
  461.      "text": [
  462.       "after insert [1, 2, 2, 'hit', 1, 2, 2, ['a', 'b'], 'b', 'a', 'c']\n"
  463.      ]
  464.     }
  465.    ],
  466.    "source": [
  467.     "B.insert(3,'hit')\n",
  468.     "print('after insert',B)"
  469.    ]
  470.   },
  471.   {
  472.    "cell_type": "code",
  473.    "execution_count": 37,
  474.    "metadata": {},
  475.    "outputs": [
  476.     {
  477.      "name": "stdout",
  478.      "output_type": "stream",
  479.      "text": [
  480.       "after sort in ascending order [1, 1, 2, 2, 2, 3, 4, 5, 7]\n",
  481.       "after sort in descending order [7, 5, 4, 3, 2, 2, 2, 1, 1]\n"
  482.      ]
  483.     }
  484.    ],
  485.    "source": [
  486.     "B=[2,3,1,2,2,1,4,5,7]\n",
  487.     "B.sort()\n",
  488.     "print('after sort in ascending order',B)\n",
  489.     "B.sort(reverse=True)\n",
  490.     "print('after sort in descending order',B)"
  491.    ]
  492.   },
  493.   {
  494.    "cell_type": "code",
  495.    "execution_count": 38,
  496.    "metadata": {},
  497.    "outputs": [
  498.     {
  499.      "name": "stdout",
  500.      "output_type": "stream",
  501.      "text": [
  502.       "after converting into list ['C', 'S', 'K']\n"
  503.      ]
  504.     }
  505.    ],
  506.    "source": [
  507.     "# Convert into list\n",
  508.     "\n",
  509.     "B = \"CSK\"\n",
  510.     "C = list(B)\n",
  511.     "\n",
  512.     "print('after converting into list',C)"
  513.    ]
  514.   },
  515.   {
  516.    "cell_type": "markdown",
  517.    "metadata": {},
  518.    "source": [
  519.     "## Tuple Operations"
  520.    ]
  521.   },
  522.   {
  523.    "cell_type": "code",
  524.    "execution_count": 40,
  525.    "metadata": {},
  526.    "outputs": [
  527.     {
  528.      "name": "stdout",
  529.      "output_type": "stream",
  530.      "text": [
  531.       "tuple3:  ('Python', 'PHP', 'HTML', 'C', '1', '2', '3', '4')\n",
  532.       "tuple4:  ('Python', 'PHP', '3', '4')\n"
  533.      ]
  534.     }
  535.    ],
  536.    "source": [
  537.     "# You can not modify tuple values. But you can perform an operation store into another tuple.\n",
  538.     "tuple1 = ('Python','PHP','HTML','C')\n",
  539.     "tuple2= ('1','2','3','4')\n",
  540.     "tuple3= tuple1+tuple2\n",
  541.     "print(\"tuple3: \", tuple3)\n",
  542.     "tuple4 = tuple1[0:2]+tuple2[2:4]\n",
  543.     "print (\"tuple4: \", tuple4) \n"
  544.    ]
  545.   },
  546.   {
  547.    "cell_type": "markdown",
  548.    "metadata": {},
  549.    "source": [
  550.     "## Dictionary Operations"
  551.    ]
  552.   },
  553.   {
  554.    "cell_type": "code",
  555.    "execution_count": 41,
  556.    "metadata": {},
  557.    "outputs": [
  558.     {
  559.      "name": "stdout",
  560.      "output_type": "stream",
  561.      "text": [
  562.       "first name\n",
  563.       "last name\n",
  564.       "33\n"
  565.      ]
  566.     }
  567.    ],
  568.    "source": [
  569.     "a = {1:\"first name\",2:\"last name\", \"age\":33}\n",
  570.     "\n",
  571.     "#print value having key=1\n",
  572.     "print(a[1])\n",
  573.     "#print value having key=2\n",
  574.     "print(a[2])\n",
  575.     "#print value having key=\"age\"\n",
  576.     "print(a[\"age\"])"
  577.    ]
  578.   },
  579.   {
  580.    "cell_type": "code",
  581.    "execution_count": 42,
  582.    "metadata": {},
  583.    "outputs": [
  584.     {
  585.      "name": "stdout",
  586.      "output_type": "stream",
  587.      "text": [
  588.       "after adding: {1: 'first name', 2: 'last name', 'age': 33, 'name': 'Sachin'}\n"
  589.      ]
  590.     }
  591.    ],
  592.    "source": [
  593.     "# Adding a key/value to a dictionary\n",
  594.     "\n",
  595.     "a['name']=\"Sachin\"\n",
  596.     "\n",
  597.     "print('after adding:',a)"
  598.    ]
  599.   },
  600.   {
  601.    "cell_type": "code",
  602.    "execution_count": 44,
  603.    "metadata": {},
  604.    "outputs": [
  605.     {
  606.      "name": "stdout",
  607.      "output_type": "stream",
  608.      "text": [
  609.       "after update: {1: 'first name', 2: 'last name', 'age': 33, 'name': 'Kohli'}\n"
  610.      ]
  611.     }
  612.    ],
  613.    "source": [
  614.     "# Update a value using key\n",
  615.     "\n",
  616.     "a['name']='Kohli'\n",
  617.     "\n",
  618.     "print('after update:',a)"
  619.    ]
  620.   },
  621.   {
  622.    "cell_type": "code",
  623.    "execution_count": 45,
  624.    "metadata": {},
  625.    "outputs": [
  626.     {
  627.      "name": "stdout",
  628.      "output_type": "stream",
  629.      "text": [
  630.       "after deleting a[\"age\"]: {1: 'first name', 2: 'last name', 'name': 'Kohli'}\n"
  631.      ]
  632.     },
  633.     {
  634.      "ename": "NameError",
  635.      "evalue": "name 'a' is not defined",
  636.      "output_type": "error",
  637.      "traceback": [
  638.       "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  639.       "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
  640.       "\u001b[0;32m<ipython-input-45-c9e1be683ef7>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      7\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'after deleting a'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
  641.       "\u001b[0;31mNameError\u001b[0m: name 'a' is not defined"
  642.      ]
  643.     }
  644.    ],
  645.    "source": [
  646.     "# delete operations\n",
  647.     "\n",
  648.     "del a['age']\n",
  649.     "\n",
  650.     "print('after deleting a[\"age\"]:', a)\n",
  651.     "\n",
  652.     "del a\n",
  653.     "\n",
  654.     "print('after deleting a',a)"
  655.    ]
  656.   },
  657.   {
  658.    "cell_type": "code",
  659.    "execution_count": 46,
  660.    "metadata": {},
  661.    "outputs": [
  662.     {
  663.      "name": "stdout",
  664.      "output_type": "stream",
  665.      "text": [
  666.       "{1: 'first name', 2: 'last name', 'age': 33}\n"
  667.      ]
  668.     }
  669.    ],
  670.    "source": [
  671.     "# copying a dictionary\n",
  672.     "a = {1:\"first name\",2:\"last name\", \"age\":33}\n",
  673.     "\n",
  674.     "b = a.copy()\n",
  675.     "\n",
  676.     "print(b)\n"
  677.    ]
  678.   },
  679.   {
  680.    "cell_type": "code",
  681.    "execution_count": 48,
  682.    "metadata": {},
  683.    "outputs": [
  684.     {
  685.      "name": "stdout",
  686.      "output_type": "stream",
  687.      "text": [
  688.       "{1: 'date', 2: 'last name', 'age': 33} , {1: 'first name', 2: 'last name', 'age': 33}\n"
  689.      ]
  690.     }
  691.    ],
  692.    "source": [
  693.     "a[1]='date'\n",
  694.     "print(a,',',b)"
  695.    ]
  696.   },
  697.   {
  698.    "cell_type": "code",
  699.    "execution_count": 49,
  700.    "metadata": {},
  701.    "outputs": [
  702.     {
  703.      "name": "stdout",
  704.      "output_type": "stream",
  705.      "text": [
  706.       "{1: 'date', 2: 'last name', 'age': 33, 'place': 'Chennai'}\n"
  707.      ]
  708.     }
  709.    ],
  710.    "source": [
  711.     "c = a\n",
  712.     "\n",
  713.     "c['place']='Chennai'\n",
  714.     "\n",
  715.     "print(a)"
  716.    ]
  717.   },
  718.   {
  719.    "cell_type": "markdown",
  720.    "metadata": {},
  721.    "source": [
  722.     "## Branching and looping"
  723.    ]
  724.   },
  725.   {
  726.    "cell_type": "code",
  727.    "execution_count": 53,
  728.    "metadata": {},
  729.    "outputs": [
  730.     {
  731.      "name": "stdout",
  732.      "output_type": "stream",
  733.      "text": [
  734.       "true\n"
  735.      ]
  736.     }
  737.    ],
  738.    "source": [
  739.     "a = [1,2,3,4,5]\n",
  740.     "if 1 in a:\n",
  741.     "    print('true')\n",
  742.     "    "
  743.    ]
  744.   },
  745.   {
  746.    "cell_type": "code",
  747.    "execution_count": 55,
  748.    "metadata": {},
  749.    "outputs": [
  750.     {
  751.      "name": "stdout",
  752.      "output_type": "stream",
  753.      "text": [
  754.       "false\n"
  755.      ]
  756.     }
  757.    ],
  758.    "source": [
  759.     "if 6 in a:\n",
  760.     "    print('true')\n",
  761.     "else:\n",
  762.     "    print('false')"
  763.    ]
  764.   },
  765.   {
  766.    "cell_type": "code",
  767.    "execution_count": 58,
  768.    "metadata": {},
  769.    "outputs": [
  770.     {
  771.      "name": "stdout",
  772.      "output_type": "stream",
  773.      "text": [
  774.       "1 is there\n"
  775.      ]
  776.     }
  777.    ],
  778.    "source": [
  779.     "if 8 in a:\n",
  780.     "    print('8 is there')\n",
  781.     "elif 1 in a:\n",
  782.     "    print('1 is there')\n",
  783.     "else:\n",
  784.     "    print('nothing')"
  785.    ]
  786.   },
  787.   {
  788.    "cell_type": "markdown",
  789.    "metadata": {},
  790.    "source": [
  791.     "## For loop"
  792.    ]
  793.   },
  794.   {
  795.    "cell_type": "code",
  796.    "execution_count": 59,
  797.    "metadata": {},
  798.    "outputs": [
  799.     {
  800.      "name": "stdout",
  801.      "output_type": "stream",
  802.      "text": [
  803.       "0\n",
  804.       "2\n",
  805.       "4\n"
  806.      ]
  807.     }
  808.    ],
  809.    "source": [
  810.     "for i in range(0,5,2):\n",
  811.     "    print(i)"
  812.    ]
  813.   },
  814.   {
  815.    "cell_type": "code",
  816.    "execution_count": 61,
  817.    "metadata": {},
  818.    "outputs": [
  819.     {
  820.      "name": "stdout",
  821.      "output_type": "stream",
  822.      "text": [
  823.       "1\n",
  824.       "2\n",
  825.       "3\n",
  826.       "4\n",
  827.       "5\n"
  828.      ]
  829.     }
  830.    ],
  831.    "source": [
  832.     "for each in a:\n",
  833.     "    print(each)"
  834.    ]
  835.   },
  836.   {
  837.    "cell_type": "code",
  838.    "execution_count": 62,
  839.    "metadata": {},
  840.    "outputs": [
  841.     {
  842.      "name": "stdout",
  843.      "output_type": "stream",
  844.      "text": [
  845.       "0\n",
  846.       "1\n",
  847.       "2\n",
  848.       "3\n",
  849.       "4\n"
  850.      ]
  851.     }
  852.    ],
  853.    "source": [
  854.     "for j in range(5):\n",
  855.     "    print(j)"
  856.    ]
  857.   },
  858.   {
  859.    "cell_type": "markdown",
  860.    "metadata": {},
  861.    "source": [
  862.     "## While loop"
  863.    ]
  864.   },
  865.   {
  866.    "cell_type": "code",
  867.    "execution_count": 66,
  868.    "metadata": {},
  869.    "outputs": [
  870.     {
  871.      "name": "stdout",
  872.      "output_type": "stream",
  873.      "text": [
  874.       "1\n",
  875.       "3\n",
  876.       "6\n",
  877.       "10\n",
  878.       "15\n",
  879.       "21\n",
  880.       "28\n",
  881.       "36\n",
  882.       "45\n"
  883.      ]
  884.     }
  885.    ],
  886.    "source": [
  887.     "sum = 0\n",
  888.     "count = 1\n",
  889.     "while (count < 10):\n",
  890.     "    sum = sum + count\n",
  891.     "    print (sum)\n",
  892.     "    count= count + 1"
  893.    ]
  894.   },
  895.   {
  896.    "cell_type": "code",
  897.    "execution_count": 67,
  898.    "metadata": {},
  899.    "outputs": [
  900.     {
  901.      "name": "stdout",
  902.      "output_type": "stream",
  903.      "text": [
  904.       "1\n",
  905.       "3\n",
  906.       "6\n",
  907.       "10\n",
  908.       "15\n"
  909.      ]
  910.     }
  911.    ],
  912.    "source": [
  913.     "sum = 0\n",
  914.     "count = 1\n",
  915.     "while (count < 10):\n",
  916.     "    sum = sum + count\n",
  917.     "    print (sum)\n",
  918.     "    if sum == 15:\n",
  919.     "        break\n",
  920.     "    count= count + 1"
  921.    ]
  922.   },
  923.   {
  924.    "cell_type": "code",
  925.    "execution_count": null,
  926.    "metadata": {},
  927.    "outputs": [],
  928.    "source": []
  929.   }
  930.  ],
  931.  "metadata": {
  932.   "kernelspec": {
  933.    "display_name": "Python 3",
  934.    "language": "python",
  935.    "name": "python3"
  936.   },
  937.   "language_info": {
  938.    "codemirror_mode": {
  939.     "name": "ipython",
  940.     "version": 3
  941.    },
  942.    "file_extension": ".py",
  943.    "mimetype": "text/x-python",
  944.    "name": "python",
  945.    "nbconvert_exporter": "python",
  946.    "pygments_lexer": "ipython3",
  947.    "version": "3.6.8"
  948.   }
  949.  },
  950.  "nbformat": 4,
  951.  "nbformat_minor": 2
  952. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top