CoolFace
Datasetpublic

Ace-xvi/Generative_AI

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes20downloads
Day 6-01-07-2023.ipynb1714 linesDownload Raw Back to 1_Adrash Python Session
1{2 "cells": [3  {4   "cell_type": "markdown",5   "id": "2dceb897",6   "metadata": {},7   "source": [8    "# Agenda\n",9    "- Recap \n",10    "- Continue with set functions\n",11    "- if else\n",12    "- One line if else\n",13    "- for loop\n",14    "- nested for loop\n",15    "- while\n",16    "- List comprehensions\n",17    "- Nested list comprehensions\n",18    "- Dictionary comprehensions"19   ]20  },21  {22   "cell_type": "markdown",23   "id": "35824224",24   "metadata": {},25   "source": [26    "### Recap\n",27    "- Use \n",28    "- "29   ]30  },31  {32   "cell_type": "code",33   "execution_count": 2,34   "id": "c57035d2",35   "metadata": {},36   "outputs": [],37   "source": [38    "b = {'a','b','a',1,2,5,6}"39   ]40  },41  {42   "cell_type": "code",43   "execution_count": 3,44   "id": "bc01cfe9",45   "metadata": {},46   "outputs": [47    {48     "data": {49      "text/plain": [50       "set"51      ]52     },53     "execution_count": 3,54     "metadata": {},55     "output_type": "execute_result"56    }57   ],58   "source": [59    "type(b)"60   ]61  },62  {63   "cell_type": "code",64   "execution_count": 4,65   "id": "9ef6378c",66   "metadata": {},67   "outputs": [68    {69     "data": {70      "text/plain": [71       "{1, 2, 5, 6, 'a', 'b'}"72      ]73     },74     "execution_count": 4,75     "metadata": {},76     "output_type": "execute_result"77    }78   ],79   "source": [80    "b"81   ]82  },83  {84   "cell_type": "code",85   "execution_count": 6,86   "id": "83f95125",87   "metadata": {},88   "outputs": [],89   "source": [90    "d = {'a':1,'b':2}"91   ]92  },93  {94   "cell_type": "code",95   "execution_count": 7,96   "id": "0058d665",97   "metadata": {},98   "outputs": [99    {100     "ename": "TypeError",101     "evalue": "unhashable type: 'list'",102     "output_type": "error",103     "traceback": [104      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",105      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",106      "Input \u001b[1;32mIn [7]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# dictionay keys will not accept mutable datatype\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m d \u001b[38;5;241m=\u001b[39m {[\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m]:\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mBanglore\u001b[39m\u001b[38;5;124m'\u001b[39m}\n",107      "\u001b[1;31mTypeError\u001b[0m: unhashable type: 'list'"108     ]109    }110   ],111   "source": [112    "# dictionay keys will not accept mutable datatype\n",113    "# For list as key we will get error. Because list is mutable\n",114    "d = {[1,2]:'Banglore'}"115   ]116  },117  {118   "cell_type": "code",119   "execution_count": 11,120   "id": "ad1a32b3",121   "metadata": {},122   "outputs": [],123   "source": [124    "d = {1+8j:'Banglore'}"125   ]126  },127  {128   "cell_type": "code",129   "execution_count": 12,130   "id": "cafac374",131   "metadata": {},132   "outputs": [133    {134     "data": {135      "text/plain": [136       "{(1+8j): 'Banglore'}"137      ]138     },139     "execution_count": 12,140     "metadata": {},141     "output_type": "execute_result"142    }143   ],144   "source": [145    "d"146   ]147  },148  {149   "cell_type": "code",150   "execution_count": null,151   "id": "5db9cc0b",152   "metadata": {},153   "outputs": [],154   "source": [155    "# integer,string,float,bool,tuple,complex  --- Are immutable datatypes and only these are allowed as keys for a dictionary"156   ]157  },158  {159   "cell_type": "markdown",160   "id": "9abc0c5c",161   "metadata": {},162   "source": [163    "- Is dictionary allowed as a key in a dictionary ?\n",164    "- No"165   ]166  },167  {168   "cell_type": "code",169   "execution_count": 27,170   "id": "d5d7ec33",171   "metadata": {},172   "outputs": [],173   "source": [174    "# Below statement will result in an error\n",175    "# Employee_details = {{96859:'Adarsh'}:{'Address':{'Street':'MG Road','City':'Banglore','State':'Karnataka'}}}\n",176    "# Variable name        key                  value"177   ]178  },179  {180   "cell_type": "markdown",181   "id": "e86669bf",182   "metadata": {},183   "source": [184    "- Is dictionary allowed as a value in a dictionary ?\n",185    "- Yes"186   ]187  },188  {189   "cell_type": "code",190   "execution_count": 17,191   "id": "0846ef25",192   "metadata": {},193   "outputs": [],194   "source": [195    "Employee_details = {90345:{'Name':'Adarsh','Address':{'Street':'MG Road','City':'Banglore','State':'Karnataka'}},\\\n",196    "                    64532:{'Name':'Mark','Address':{'Street':'Brigade road','City':'Hyderabad','State':'Telangana'}}}"197   ]198  },199  {200   "cell_type": "code",201   "execution_count": 23,202   "id": "df767b59",203   "metadata": {},204   "outputs": [205    {206     "name": "stdout",207     "output_type": "stream",208     "text": [209      "Banglore\n",210      "Adarsh\n"211     ]212    }213   ],214   "source": [215    "print(Employee_details[90345]['Address']['City'])\n",216    "print(Employee_details[90345]['Name'])"217   ]218  },219  {220   "cell_type": "markdown",221   "id": "7f649c63",222   "metadata": {},223   "source": [224    "### Set\n",225    "- Set is heterogeneous\n",226    "- It is mutable\n",227    "- Unordered\n",228    "- It can contain only unique values\n",229    "- Only immutable elements are allowed"230   ]231  },232  {233   "cell_type": "code",234   "execution_count": 36,235   "id": "37193ce6",236   "metadata": {},237   "outputs": [],238   "source": [239    "s1 = {}\n",240    "s2 = set('Banglore')\n",241    "s3 = set('Chennai')\n",242    "s4 = set('Mumbai')\n",243    "s5 = set('goa')\n",244    "s6 = set([1,2,3])"245   ]246  },247  {248   "cell_type": "code",249   "execution_count": 37,250   "id": "8bd3052c",251   "metadata": {},252   "outputs": [253    {254     "name": "stdout",255     "output_type": "stream",256     "text": [257      "<class 'dict'>\n",258      "<class 'set'>\n"259     ]260    }261   ],262   "source": [263    "print(type(s1))\n",264    "print(type(s2))"265   ]266  },267  {268   "cell_type": "code",269   "execution_count": 38,270   "id": "97f6c95d",271   "metadata": {},272   "outputs": [273    {274     "data": {275      "text/plain": [276       "{1, 2, 3, 'a', 'g', 'o'}"277      ]278     },279     "execution_count": 38,280     "metadata": {},281     "output_type": "execute_result"282    }283   ],284   "source": [285    "s5.union(s6)"286   ]287  },288  {289   "cell_type": "code",290   "execution_count": 39,291   "id": "c381dedb",292   "metadata": {},293   "outputs": [],294   "source": [295    "s5.update('hi')"296   ]297  },298  {299   "cell_type": "code",300   "execution_count": 40,301   "id": "4500af92",302   "metadata": {},303   "outputs": [304    {305     "data": {306      "text/plain": [307       "{'a', 'g', 'h', 'i', 'o'}"308      ]309     },310     "execution_count": 40,311     "metadata": {},312     "output_type": "execute_result"313    }314   ],315   "source": [316    "s5"317   ]318  },319  {320   "cell_type": "code",321   "execution_count": 41,322   "id": "5a148496",323   "metadata": {},324   "outputs": [],325   "source": [326    "s5.add('hi')"327   ]328  },329  {330   "cell_type": "code",331   "execution_count": 42,332   "id": "f76473ce",333   "metadata": {},334   "outputs": [335    {336     "data": {337      "text/plain": [338       "{'a', 'g', 'h', 'hi', 'i', 'o'}"339      ]340     },341     "execution_count": 42,342     "metadata": {},343     "output_type": "execute_result"344    }345   ],346   "source": []347  },348  {349   "cell_type": "markdown",350   "id": "59a56194",351   "metadata": {},352   "source": [353    "### Difference between intersection and intersection updtae"354   ]355  },356  {357   "cell_type": "code",358   "execution_count": 45,359   "id": "d3d0fb9c",360   "metadata": {},361   "outputs": [362    {363     "data": {364      "text/plain": [365       "{'a', 'e', 'n'}"366      ]367     },368     "execution_count": 45,369     "metadata": {},370     "output_type": "execute_result"371    }372   ],373   "source": [374    "s2 = set('Banglore')\n",375    "s3 = set('Chennai')\n",376    "s2.intersection(s3)"377   ]378  },379  {380   "cell_type": "code",381   "execution_count": 46,382   "id": "6dd56c57",383   "metadata": {},384   "outputs": [385    {386     "data": {387      "text/plain": [388       "{'B', 'a', 'e', 'g', 'l', 'n', 'o', 'r'}"389      ]390     },391     "execution_count": 46,392     "metadata": {},393     "output_type": "execute_result"394    }395   ],396   "source": [397    "s2"398   ]399  },400  {401   "cell_type": "code",402   "execution_count": 47,403   "id": "07213baa",404   "metadata": {},405   "outputs": [406    {407     "data": {408      "text/plain": [409       "{'C', 'a', 'e', 'h', 'i', 'n'}"410      ]411     },412     "execution_count": 47,413     "metadata": {},414     "output_type": "execute_result"415    }416   ],417   "source": [418    "s3"419   ]420  },421  {422   "cell_type": "code",423   "execution_count": 60,424   "id": "9bdeed27",425   "metadata": {},426   "outputs": [427    {428     "name": "stdout",429     "output_type": "stream",430     "text": [431      "{'l', 'n', 'e', 'B', 'o', 'r', 'g', 'a'}\n",432      "{'a', 'e', 'n'}\n"433     ]434    }435   ],436   "source": [437    "s2 = set('Banglore')\n",438    "s3 = set('Chennai')\n",439    "s3.intersection_update(s2)\n",440    "print(s2)\n",441    "print(s3)"442   ]443  },444  {445   "cell_type": "code",446   "execution_count": 53,447   "id": "60f71fa7",448   "metadata": {},449   "outputs": [450    {451     "name": "stdout",452     "output_type": "stream",453     "text": [454      "{'a', 'e', 'n'}\n",455      "{'C', 'n', 'e', 'i', 'h', 'a'}\n"456     ]457    }458   ],459   "source": [460    "s2 = set('Banglore')\n",461    "s3 = set('Chennai')\n",462    "s2.intersection_update(s3)\n",463    "print(s2)\n",464    "print(s3)"465   ]466  },467  {468   "cell_type": "code",469   "execution_count": 59,470   "id": "2e45446d",471   "metadata": {},472   "outputs": [473    {474     "name": "stdout",475     "output_type": "stream",476     "text": [477      "{'a', 'e', 'n'}\n",478      "{'C', 'n', 'e', 'i', 'h', 'a'}\n"479     ]480    }481   ],482   "source": [483    "## Both the codes above and below are equivalent\n",484    "s2 = set('Banglore')\n",485    "s3 = set('Chennai')\n",486    "s3.intersection(s2)\n",487    "s2 = res\n",488    "print(s2)\n",489    "print(s3)"490   ]491  },492  {493   "cell_type": "code",494   "execution_count": 57,495   "id": "a0ff8c38",496   "metadata": {},497   "outputs": [498    {499     "name": "stdout",500     "output_type": "stream",501     "text": [502      "{'a', 'e', 'n'}\n",503      "{'C', 'n', 'e', 'i', 'h', 'a'}\n"504     ]505    }506   ],507   "source": [508    "## Both the codes above and below are equivalent\n",509    "s2 = set('Banglore')\n",510    "s3 = set('Chennai')\n",511    "s2.intersection(s3)\n",512    "s2 = res\n",513    "print(s2)\n",514    "print(s3)"515   ]516  },517  {518   "cell_type": "code",519   "execution_count": null,520   "id": "f6936380",521   "metadata": {},522   "outputs": [],523   "source": []524  },525  {526   "cell_type": "code",527   "execution_count": 49,528   "id": "6cdcce77",529   "metadata": {},530   "outputs": [531    {532     "data": {533      "text/plain": [534       "{'a', 'e', 'n'}"535      ]536     },537     "execution_count": 49,538     "metadata": {},539     "output_type": "execute_result"540    }541   ],542   "source": [543    "s2"544   ]545  },546  {547   "cell_type": "code",548   "execution_count": 50,549   "id": "20ff89e5",550   "metadata": {},551   "outputs": [552    {553     "data": {554      "text/plain": [555       "{'C', 'a', 'e', 'h', 'i', 'n'}"556      ]557     },558     "execution_count": 50,559     "metadata": {},560     "output_type": "execute_result"561    }562   ],563   "source": [564    "s3"565   ]566  },567  {568   "cell_type": "code",569   "execution_count": 54,570   "id": "8c47b0e6",571   "metadata": {},572   "outputs": [573    {574     "name": "stdout",575     "output_type": "stream",576     "text": [577      "Help on method_descriptor:\n",578      "\n",579      "intersection_update(...)\n",580      "    Update a set with the intersection of itself and another.\n",581      "\n"582     ]583    }584   ],585   "source": [586    "help(set.intersection_update)"587   ]588  },589  {590   "cell_type": "code",591   "execution_count": 55,592   "id": "506a177c",593   "metadata": {},594   "outputs": [595    {596     "name": "stdout",597     "output_type": "stream",598     "text": [599      "Help on method_descriptor:\n",600      "\n",601      "intersection(...)\n",602      "    Return the intersection of two sets as a new set.\n",603      "    \n",604      "    (i.e. all elements that are in both sets.)\n",605      "\n"606     ]607    }608   ],609   "source": [610    "help(set.intersection)"611   ]612  },613  {614   "cell_type": "markdown",615   "id": "8117775a",616   "metadata": {},617   "source": [618    "### Understanding pop and discard"619   ]620  },621  {622   "cell_type": "code",623   "execution_count": 61,624   "id": "119ba18e",625   "metadata": {},626   "outputs": [627    {628     "name": "stdout",629     "output_type": "stream",630     "text": [631      "Help on method_descriptor:\n",632      "\n",633      "discard(...)\n",634      "    Remove an element from a set if it is a member.\n",635      "    \n",636      "    If the element is not a member, do nothing.\n",637      "\n"638     ]639    }640   ],641   "source": [642    "help(set.discard)"643   ]644  },645  {646   "cell_type": "code",647   "execution_count": 62,648   "id": "75a806d5",649   "metadata": {},650   "outputs": [],651   "source": [652    "s5 = set('goa')\n",653    "s5.discard('o')"654   ]655  },656  {657   "cell_type": "code",658   "execution_count": 63,659   "id": "77345472",660   "metadata": {},661   "outputs": [662    {663     "data": {664      "text/plain": [665       "{'a', 'g'}"666      ]667     },668     "execution_count": 63,669     "metadata": {},670     "output_type": "execute_result"671    }672   ],673   "source": [674    "s5"675   ]676  },677  {678   "cell_type": "code",679   "execution_count": 66,680   "id": "b7488e7f",681   "metadata": {},682   "outputs": [683    {684     "name": "stdout",685     "output_type": "stream",686     "text": [687      "Help on method_descriptor:\n",688      "\n",689      "pop(...)\n",690      "    Remove and return an arbitrary set element.\n",691      "    Raises KeyError if the set is empty.\n",692      "\n"693     ]694    }695   ],696   "source": [697    "help(set.pop)"698   ]699  },700  {701   "cell_type": "code",702   "execution_count": 65,703   "id": "d7be627d",704   "metadata": {},705   "outputs": [706    {707     "data": {708      "text/plain": [709       "'g'"710      ]711     },712     "execution_count": 65,713     "metadata": {},714     "output_type": "execute_result"715    }716   ],717   "source": [718    "s5 = set('goa')\n",719    "s5.pop()"720   ]721  },722  {723   "cell_type": "code",724   "execution_count": 67,725   "id": "37eec965",726   "metadata": {},727   "outputs": [728    {729     "data": {730      "text/plain": [731       "{'a', 'o'}"732      ]733     },734     "execution_count": 67,735     "metadata": {},736     "output_type": "execute_result"737    }738   ],739   "source": [740    "s5"741   ]742  },743  {744   "cell_type": "markdown",745   "id": "e0f8ed3d",746   "metadata": {},747   "source": [748    "### Understanding isdisdjoint"749   ]750  },751  {752   "cell_type": "code",753   "execution_count": 70,754   "id": "1940adc4",755   "metadata": {},756   "outputs": [757    {758     "data": {759      "text/plain": [760       "True"761      ]762     },763     "execution_count": 70,764     "metadata": {},765     "output_type": "execute_result"766    }767   ],768   "source": [769    "s1 = set('goa')\n",770    "s2 = set('pune')\n",771    "s1.isdisjoint(s2)"772   ]773  },774  {775   "cell_type": "code",776   "execution_count": 71,777   "id": "f402ddd8",778   "metadata": {},779   "outputs": [780    {781     "data": {782      "text/plain": [783       "False"784      ]785     },786     "execution_count": 71,787     "metadata": {},788     "output_type": "execute_result"789    }790   ],791   "source": [792    "s1 = set('chennai')\n",793    "s2 = set('pune')\n",794    "s1.isdisjoint(s2)"795   ]796  },797  {798   "cell_type": "markdown",799   "id": "4dbf3a35",800   "metadata": {},801   "source": [802    "### Difference between discard and remove"803   ]804  },805  {806   "cell_type": "code",807   "execution_count": 72,808   "id": "7d667fae",809   "metadata": {},810   "outputs": [],811   "source": [812    "s1.remove('n')"813   ]814  },815  {816   "cell_type": "code",817   "execution_count": 73,818   "id": "11b7bf35",819   "metadata": {},820   "outputs": [821    {822     "data": {823      "text/plain": [824       "{'a', 'c', 'e', 'h', 'i'}"825      ]826     },827     "execution_count": 73,828     "metadata": {},829     "output_type": "execute_result"830    }831   ],832   "source": [833    "s1"834   ]835  },836  {837   "cell_type": "code",838   "execution_count": 74,839   "id": "83261524",840   "metadata": {},841   "outputs": [842    {843     "ename": "KeyError",844     "evalue": "'z'",845     "output_type": "error",846     "traceback": [847      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",848      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",849      "Input \u001b[1;32mIn [74]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43ms1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mremove\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mz\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",850      "\u001b[1;31mKeyError\u001b[0m: 'z'"851     ]852    }853   ],854   "source": [855    "s1.remove('z')"856   ]857  },858  {859   "cell_type": "code",860   "execution_count": 75,861   "id": "ff6cf192",862   "metadata": {},863   "outputs": [],864   "source": [865    "s1.discard('z')"866   ]867  },868  {869   "cell_type": "code",870   "execution_count": 79,871   "id": "0a14cebb",872   "metadata": {},873   "outputs": [874    {875     "data": {876      "text/plain": [877       "True"878      ]879     },880     "execution_count": 79,881     "metadata": {},882     "output_type": "execute_result"883    }884   ],885   "source": [886    "s1 = set('banglore')\n",887    "s2 = set('goa')\n",888    "s2.issubset(s1)"889   ]890  },891  {892   "cell_type": "code",893   "execution_count": 80,894   "id": "fdeb0176",895   "metadata": {},896   "outputs": [897    {898     "data": {899      "text/plain": [900       "True"901      ]902     },903     "execution_count": 80,904     "metadata": {},905     "output_type": "execute_result"906    }907   ],908   "source": [909    "s1.issuperset(s2)"910   ]911  },912  {913   "cell_type": "markdown",914   "id": "f4649563",915   "metadata": {},916   "source": [917    "### Conditional statements \n",918    "- if...else\n",919    "- Single line if else or ternary operator\n",920    "- if....elif\n",921    "- nested if else"922   ]923  },924  {925   "cell_type": "code",926   "execution_count": 90,927   "id": "cf43fa4c",928   "metadata": {},929   "outputs": [],930   "source": [931    "### if .... else\n",932    "### if condition:\n",933    "###     statements to execute when condition is True\n",934    "### else:\n",935    "###     statements to execute when condition is False"936   ]937  },938  {939   "cell_type": "code",940   "execution_count": 96,941   "id": "385ce30e",942   "metadata": {},943   "outputs": [944    {945     "name": "stdout",946     "output_type": "stream",947     "text": [948      "Please enter the score\n",949      "56\n",950      "Result is Pass\n"951     ]952    }953   ],954   "source": [955    "score = int(input('Please enter the score\\n'))\n",956    "if score>35:\n",957    "    print('Result is Pass')\n",958    "else:\n",959    "    print('Result is Fail')"960   ]961  },962  {963   "cell_type": "code",964   "execution_count": 97,965   "id": "5b065035",966   "metadata": {},967   "outputs": [968    {969     "name": "stdout",970     "output_type": "stream",971     "text": [972      "Please enter the score\n",973      "45\n",974      "\n",975      "Score is       45\n",976      "Result is Pass\n"977     ]978    }979   ],980   "source": [981    "score = int(input('Please enter the score\\n'))\n",982    "\n",983    "if score>35:\n",984    "    print('\\nScore is       '+ str(score))\n",985    "    print('Result is Pass')\n",986    "else:\n",987    "    print('\\nScore is       '+ str(score))\n",988    "    print('Result is Fail')"989   ]990  },991  {992   "cell_type": "code",993   "execution_count": 91,994   "id": "00e00894",995   "metadata": {},996   "outputs": [997    {998     "name": "stdout",999     "output_type": "stream",1000     "text": [1001      "Score is 35\n",1002      "Result is Fail\n"1003     ]1004    }1005   ],1006   "source": []1007  },1008  {1009   "cell_type": "code",1010   "execution_count": 102,1011   "id": "36feae57",1012   "metadata": {},1013   "outputs": [1014    {1015     "data": {1016      "text/plain": [1017       "'Score is            35'"1018      ]1019     },1020     "execution_count": 102,1021     "metadata": {},1022     "output_type": "execute_result"1023    }1024   ],1025   "source": [1026    "'Score is            '+'35'"1027   ]1028  },1029  {1030   "cell_type": "code",1031   "execution_count": 103,1032   "id": "d7c4fc4e",1033   "metadata": {},1034   "outputs": [1035    {1036     "data": {1037      "text/plain": [1038       "'Score is             35'"1039      ]1040     },1041     "execution_count": 103,1042     "metadata": {},1043     "output_type": "execute_result"1044    }1045   ],1046   "source": [1047    "'Score is             '+str(35)"1048   ]1049  },1050  {1051   "cell_type": "code",1052   "execution_count": 120,1053   "id": "88c875e1",1054   "metadata": {},1055   "outputs": [1056    {1057     "name": "stdout",1058     "output_type": "stream",1059     "text": [1060      "Please enter the score\n",1061      "556\n",1062      "Score is invalid\n"1063     ]1064    }1065   ],1066   "source": [1067    "score = int(input('Please enter the score\\n'))\n",1068    "\n",1069    "if score>100 or score<0:\n",1070    "    print('Score is invalid')\n",1071    "elif score<35:\n",1072    "    print('Result is Fail')\n",1073    "else:\n",1074    "    print('Result is pass')"1075   ]1076  },1077  {1078   "cell_type": "code",1079   "execution_count": 125,1080   "id": "a3ca6a67",1081   "metadata": {},1082   "outputs": [1083    {1084     "name": "stdout",1085     "output_type": "stream",1086     "text": [1087      "Please enter the score\n",1088      "45\n",1089      "Result is pass\n"1090     ]1091    }1092   ],1093   "source": [1094    "score = int(input('Please enter the score\\n'))\n",1095    "\n",1096    "if score>100 or score<0:\n",1097    "    print('Score is invalid')\n",1098    "elif score<35:\n",1099    "    print('Result is Fail')\n",1100    "else:\n",1101    "    print('Result is pass')"1102   ]1103  },1104  {1105   "cell_type": "code",1106   "execution_count": 126,1107   "id": "7ecb91e9",1108   "metadata": {},1109   "outputs": [1110    {1111     "name": "stdout",1112     "output_type": "stream",1113     "text": [1114      "Please enter the score\n",1115      "78\n",1116      "Result is pass\n"1117     ]1118    }1119   ],1120   "source": [1121    "### Nested if else\n",1122    "score = int(input('Please enter the score\\n'))\n",1123    "if score>100:\n",1124    "    print('Score is invalid')\n",1125    "elif score<35:\n",1126    "    if score<0:\n",1127    "        print('Score is invalid')\n",1128    "    else:\n",1129    "        print('Result is Fail')\n",1130    "else:\n",1131    "    print('Result is pass')"1132   ]1133  },1134  {1135   "cell_type": "code",1136   "execution_count": 137,1137   "id": "0f5e8f70",1138   "metadata": {},1139   "outputs": [],1140   "source": [1141    "### Write a code to except time and tell weather its morning, evening, afternoon or night"1142   ]1143  },1144  {1145   "cell_type": "code",1146   "execution_count": 213,1147   "id": "882dab4d",1148   "metadata": {},1149   "outputs": [1150    {1151     "name": "stdout",1152     "output_type": "stream",1153     "text": [1154      "Please enter the time in HH:MM AM\\PM\n",1155      "1:12 AM\n"1156     ]1157    }1158   ],1159   "source": [1160    "time_str = input('Please enter the time in HH:MM AM\\PM\\n')\n",1161    "# print(time_str)"1162   ]1163  },1164  {1165   "cell_type": "code",1166   "execution_count": 214,1167   "id": "96a97d87",1168   "metadata": {},1169   "outputs": [1170    {1171     "data": {1172      "text/plain": [1173       "['1:12', 'AM']"1174      ]1175     },1176     "execution_count": 214,1177     "metadata": {},1178     "output_type": "execute_result"1179    }1180   ],1181   "source": [1182    "time_str.split()"1183   ]1184  },1185  {1186   "cell_type": "code",1187   "execution_count": 215,1188   "id": "d8eac57e",1189   "metadata": {},1190   "outputs": [1191    {1192     "name": "stdout",1193     "output_type": "stream",1194     "text": [1195      "AM\n",1196      "1:12\n",1197      "1\n",1198      "12\n"1199     ]1200    }

Showing the first 1,200 of 1714 lines. Download the file for the rest.