From c7d844824d6aa0a2affee16e9a1a53bc501a4eac Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 14:11:27 +0530 Subject: [PATCH 01/12] step 1 completed --- Python-ifed.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..10e4949 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -62,15 +62,15 @@ "### Describe what each of the following means\n", "\n", "#### Production\n", - "(Insert answer here)\n", + "Any code that is ready to be used by its userbase after testing.\n", "#### Clean \n", - "(Insert answer here)\n", + "A code which is easy to understand, modify and test.\n", "#### Modular\n", - "(Insert answer here)\n", + "Modular means to divide the code into different modules. It makes the program reusable and easy to maintain.\n", "#### Module\n", - "(Insert answer here)\n", + "Module is a file which has definitions which can be used in a script or in an interactive instance of the interpretor\n", "#### Refactoring code\n", - "(Insert answer here)" + "It is the process of restructuring the code without changing or adding anything to its functionality. It makes the code more readable." ] }, { From d3836cc14767ea1f0684a9291614a507cef280ad Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 14:13:41 +0530 Subject: [PATCH 02/12] step 2 complete --- Python-ifed.ipynb | 113 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 107 insertions(+), 6 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 10e4949..b73b3cb 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -93,9 +93,59 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " Season city date team 1 \\\n", + "id \n", + "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n", + "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n", + "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n", + "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n", + "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n", + "\n", + " team 2 toss winner toss decision \\\n", + "id \n", + "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n", + "2 Rising Pune Supergiant Rising Pune Supergiant field \n", + "3 Kolkata Knight Riders Kolkata Knight Riders field \n", + "4 Kings XI Punjab Kings XI Punjab field \n", + "5 Delhi Daredevils Royal Challengers Bangalore bat \n", + "\n", + " result dl applied winner win by runs \\\n", + "id \n", + "1 normal 0 Sunrisers Hyderabad 35 \n", + "2 normal 0 Rising Pune Supergiant 0 \n", + "3 normal 0 Kolkata Knight Riders 0 \n", + "4 normal 0 Kings XI Punjab 0 \n", + "5 normal 0 Royal Challengers Bangalore 15 \n", + "\n", + " win by wickets player of match venue \\\n", + "id \n", + "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n", + "2 7 SPD Smith Maharashtra Cricket Association Stadium \n", + "3 10 CA Lynn Saurashtra Cricket Association Stadium \n", + "4 6 GJ Maxwell Holkar Cricket Stadium \n", + "5 0 KM Jadhav M Chinnaswamy Stadium \n", + "\n", + " umpire 1 umpire 2 \n", + "id \n", + "1 AY Dandekar NJ Llong \n", + "2 A Nand Kishore S Ravi \n", + "3 Nitin Menon CK Nandan \n", + "4 AK Chaudhary C Shamshuddin \n", + "5 NaN NaN " + ], + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Seasoncitydateteam 1team 2toss winnertoss decisionresultdl appliedwinnerwin by runswin by wicketsplayer of matchvenueumpire 1umpire 2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\n
" + }, + "metadata": {}, + "execution_count": 2 + } + ], "source": [ "import pandas as pd\n", "df = pd.read_csv('matches.csv', sep=',')\n", @@ -167,11 +217,62 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " Season city date team_1 \\\n", + "id \n", + "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n", + "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n", + "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n", + "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n", + "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n", + "\n", + " team_2 toss_winner toss_decision \\\n", + "id \n", + "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n", + "2 Rising Pune Supergiant Rising Pune Supergiant field \n", + "3 Kolkata Knight Riders Kolkata Knight Riders field \n", + "4 Kings XI Punjab Kings XI Punjab field \n", + "5 Delhi Daredevils Royal Challengers Bangalore bat \n", + "\n", + " result dl_applied winner win_by_runs \\\n", + "id \n", + "1 normal 0 Sunrisers Hyderabad 35 \n", + "2 normal 0 Rising Pune Supergiant 0 \n", + "3 normal 0 Kolkata Knight Riders 0 \n", + "4 normal 0 Kings XI Punjab 0 \n", + "5 normal 0 Royal Challengers Bangalore 15 \n", + "\n", + " win_by_wickets player_of_match venue \\\n", + "id \n", + "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n", + "2 7 SPD Smith Maharashtra Cricket Association Stadium \n", + "3 10 CA Lynn Saurashtra Cricket Association Stadium \n", + "4 6 GJ Maxwell Holkar Cricket Stadium \n", + "5 0 KM Jadhav M Chinnaswamy Stadium \n", + "\n", + " umpire_1 umpire_2 \n", + "id \n", + "1 AY Dandekar NJ Llong \n", + "2 A Nand Kishore S Ravi \n", + "3 Nitin Menon CK Nandan \n", + "4 AK Chaudhary C Shamshuddin \n", + "5 NaN NaN " + ], + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Seasoncitydateteam_1team_2toss_winnertoss_decisionresultdl_appliedwinnerwin_by_runswin_by_wicketsplayer_of_matchvenueumpire_1umpire_2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\n
" + }, + "metadata": {}, + "execution_count": 3 + } + ], "source": [ - "# Insert your solution here" + "df.columns = df.columns.str.replace(' ','_')\n", + "df.head()" ] }, { @@ -515,7 +616,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.2-final" } }, "nbformat": 4, From 62c4d1d588185a398144442c520d0f076942b4d0 Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 14:18:21 +0530 Subject: [PATCH 03/12] step 3 completed --- Python-ifed.ipynb | 50 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index b73b3cb..a239e7e 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -309,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -320,7 +320,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -333,10 +333,6 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ "start = time.time()\n", "verified_elements = []\n", @@ -347,7 +343,11 @@ "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" - ] + ], + "cell_type": "code", + "metadata": {}, + "execution_count": null, + "outputs": [] }, { "cell_type": "markdown", @@ -357,15 +357,24 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ - "# Insert answer here\n", + "start = time.time()\n", + "verified_elements= np.intersect1d(subset_elements, all_elements)\n", "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" + ], + "cell_type": "code", + "metadata": {}, + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 0.038300514221191406 seconds\n" + ] + } ] }, { @@ -377,11 +386,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 0.011659860610961914 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start = time.time()\n", + "a =set(subset_elements)\n", + "b =set(all_elements)\n", + "verified_elements = a.intersection(b)\n", "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" From 51d80be121a0c3c450bcb7a042fcc1a99666db88 Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 14:21:34 +0530 Subject: [PATCH 04/12] step 4 completed --- step_4.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 step_4.py diff --git a/step_4.py b/step_4.py new file mode 100644 index 0000000..0d052de --- /dev/null +++ b/step_4.py @@ -0,0 +1,38 @@ +import time +import pandas as pd +import numpy as np +def by_Numpy(subset_elements,all_elements): + + + #starting of function + start = time.time() + + #Getting all the common elements using intersection1d + verified_elements= np.intersect1d(subset_elements, all_elements) + + + # print number of elements common and time taken + print(len(verified_elements)) + print('Duration: {} seconds'.format(time.time() - start)) + +by_Numpy.__doc__ = """ +This function finds number of common value from two lists using numpy + """ + +def bySets(subset_elements,all_elements): + """This function finds number of common value from two lists using numpy""" + start = time.time() + + #convert lists to sets + a =set(subset_elements) + b =set(all_elements) + + #find the elements in intersection of sets + verified_elements = a.intersection(b) + + # print number of elements common and time taken + print(len(verified_elements)) + print('Duration: {} seconds'.format(time.time() - start)) +bySets.__doc__ = """ +This function finds number of common value from two lists by converting them to sets and finding number of intersection. + """ \ No newline at end of file From d8fbcd459fdba0b70281b3f94ce9c443768d750d Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 14:24:28 +0530 Subject: [PATCH 05/12] step 5 completed --- nearest_square.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 nearest_square.py diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..d9d252d --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,8 @@ +import math +def nearest_square(n): + + if n>0: + i=int(math.sqrt(n)) + return (i*i) + else: + return 0 From f15569e8506689a2562214c9016bdf8d6345d142 Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 15:53:04 +0530 Subject: [PATCH 06/12] Completed challenge 2 --- Python-ifed.ipynb | 110 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 94 insertions(+), 16 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index a239e7e..18fbe05 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -451,9 +451,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\nrootdir: /home/siddharth/Desktop/Python-ifed-challenge\ncollected 4 items \u001b[0m\n\ntest_nearest_square.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n\n\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 0.01s\u001b[0m\u001b[32m ===============================\u001b[0m\n" + ] + } + ], "source": [ "! pytest test_nearest_square.py" ] @@ -507,11 +515,26 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ghost\npoison\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests\n", + "import json\n", + "\n", + "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n", + "res = requests.get(url)\n", + "obj = res.json()\n", + "for w in obj['types']:\n", + " print(w['type']['name'])" ] }, { @@ -525,11 +548,34 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "poison\nfairy\nground\ngrass\ndark\nbug\npsychic\nfighting\nghost\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests\n", + "import json\n", + "dam_from = set()\n", + "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n", + "res = requests.get(url)\n", + "obj = res.json()\n", + "for w in obj['types']:\n", + " link = w['type']['url']\n", + " r = requests.get(link)\n", + " detail = r.json()\n", + " for half in detail['damage_relations']['half_damage_from']:\n", + " dam_from.add(half['name'])\n", + " for double in detail['damage_relations']['double_damage_from']:\n", + " dam_from.add(double['name'])\n", + "for pokemon in dam_from:\n", + " print(pokemon)" ] }, { @@ -541,11 +587,43 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "abra\nkadabra\nalakazam\nslowpoke\nslowbro\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests\n", + "import json\n", + "\n", + "dam_from = set()\n", + "\n", + "#getting json from webpage\n", + "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n", + "res = requests.get(url)\n", + "obj = res.json()\n", + "\n", + "#running elements of obj\n", + "for w in obj['types']:\n", + "\n", + " link = w['type']['url'] \n", + " r = requests.get(link)\n", + " a = r.json()\n", + "\n", + " link1 = a['damage_relations']['double_damage_to'][1]['url']\n", + " res1 = requests.get(link1)\n", + " b = res1.json()\n", + "\n", + " for i in range(5):\n", + " print(b['pokemon'][i]['pokemon']['name'])\n", + "\n", + " break\n" ] }, { @@ -559,21 +637,21 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 11, "metadata": {}, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ "\u001b[1m============================= test session starts ==============================\u001b[0m\n", - "platform darwin -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\n", - "rootdir: /Users/abhijitramesh/development/Python-ifed\n", + "platform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\n", + "rootdir: /home/siddharth/Desktop/Python-ifed-challenge\n", "collected 4 items \u001b[0m\n", "\n", "test_abilities.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n", "\n", - "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 2.75s\u001b[0m\u001b[32m ===============================\u001b[0m\n" + "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 1.78s\u001b[0m\u001b[32m ===============================\u001b[0m\n" ] } ], From cf873db3cf2c48507334b20366518169d04e2cfe Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 16:02:03 +0530 Subject: [PATCH 07/12] update step_4.py --- step_4.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/step_4.py b/step_4.py index 0d052de..c92eb33 100644 --- a/step_4.py +++ b/step_4.py @@ -15,12 +15,14 @@ def by_Numpy(subset_elements,all_elements): print(len(verified_elements)) print('Duration: {} seconds'.format(time.time() - start)) + by_Numpy.__doc__ = """ This function finds number of common value from two lists using numpy """ + def bySets(subset_elements,all_elements): - """This function finds number of common value from two lists using numpy""" + #start of the function start = time.time() #convert lists to sets @@ -33,6 +35,8 @@ def bySets(subset_elements,all_elements): # print number of elements common and time taken print(len(verified_elements)) print('Duration: {} seconds'.format(time.time() - start)) + + bySets.__doc__ = """ This function finds number of common value from two lists by converting them to sets and finding number of intersection. """ \ No newline at end of file From c1170b4cd94b58d604159d47741310b884339e7f Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 16:05:56 +0530 Subject: [PATCH 08/12] update step_4.py --- step_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/step_4.py b/step_4.py index c92eb33..deb5ce7 100644 --- a/step_4.py +++ b/step_4.py @@ -1,9 +1,9 @@ import time import pandas as pd import numpy as np + def by_Numpy(subset_elements,all_elements): - #starting of function start = time.time() @@ -39,4 +39,4 @@ def bySets(subset_elements,all_elements): bySets.__doc__ = """ This function finds number of common value from two lists by converting them to sets and finding number of intersection. - """ \ No newline at end of file + """ From 4b788ae29b20c986f8823b141e36b68a87633f4a Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 16:20:08 +0530 Subject: [PATCH 09/12] completed challenge 2 --- ability.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ability.py diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..74b4c8d --- /dev/null +++ b/ability.py @@ -0,0 +1,15 @@ +import json,requests + +def ability(pokemon): + + abilities = [] #To store abilities + + url = 'https://pokeapi.co/api/v2/pokemon/'+pokemon + res = requests.get(url) + detail = res.json() # to get details in list + + #appending abilities to the list + for i in detail['abilities']: + abilities.append(i['ability']['name']) + + return abilities From 39576747f6b7ef9e7581590d496072355a693e86 Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 20:29:48 +0530 Subject: [PATCH 10/12] Update challenge 2 --- Python-ifed.ipynb | 83 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 18fbe05..a7800fb 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -271,7 +271,7 @@ } ], "source": [ - "df.columns = df.columns.str.replace(' ','_')\n", + "df.columns = df.columns.str.replace(' ','_') # Replacing space with underscore\n", "df.head()" ] }, @@ -358,9 +358,13 @@ }, { "source": [ + "#Starting the program\n", "start = time.time()\n", + "\n", + "#finding intersection using intersect!d()\n", "verified_elements= np.intersect1d(subset_elements, all_elements)\n", "\n", + "#printing the number of common elements\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" ], @@ -398,11 +402,16 @@ } ], "source": [ - "start = time.time()\n", + "start = time.time() #Starting the program\n", + "\n", + "#converting list to set\n", "a =set(subset_elements)\n", "b =set(all_elements)\n", + "\n", + "#finding common elements in set\n", "verified_elements = a.intersection(b)\n", "\n", + "#printing the number of common elements\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" ] @@ -530,11 +539,14 @@ "import requests\n", "import json\n", "\n", + "#Get json object \n", "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n", "res = requests.get(url)\n", "obj = res.json()\n", - "for w in obj['types']:\n", - " print(w['type']['name'])" + "\n", + "#Get information of the pokemon and then get its type name.\n", + "for info in obj['types']:\n", + " print(info['type']['name'])" ] }, { @@ -548,7 +560,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -562,18 +574,27 @@ "source": [ "import requests\n", "import json\n", - "dam_from = set()\n", + "\n", + "dam_from = set() #Stores type of pokemons this type take damage from\n", + "\n", + "#Get json object of gengar\n", "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n", "res = requests.get(url)\n", "obj = res.json()\n", - "for w in obj['types']:\n", - " link = w['type']['url']\n", + "\n", + "#run a loop to get URL of pokemon's type detail.\n", + "for info in obj['types']:\n", + " link = info['type']['url']\n", " r = requests.get(link)\n", " detail = r.json()\n", + "\n", + " #Searching for all damage gengar can take from\n", " for half in detail['damage_relations']['half_damage_from']:\n", " dam_from.add(half['name'])\n", " for double in detail['damage_relations']['double_damage_from']:\n", " dam_from.add(double['name'])\n", + "\n", + "#printing the result\n", "for pokemon in dam_from:\n", " print(pokemon)" ] @@ -587,14 +608,31 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 3, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "abra\nkadabra\nalakazam\nslowpoke\nslowbro\n" + "ghost\n", + "-------\n", + "umbreon\n", + "murkrow\n", + "sneasel\n", + "houndour\n", + "houndoom\n", + "\n", + "\n", + "psychic\n", + "-------\n", + "abra\n", + "kadabra\n", + "alakazam\n", + "slowpoke\n", + "slowbro\n", + "\n", + "\n" ] } ], @@ -602,28 +640,35 @@ "import requests\n", "import json\n", "\n", - "dam_from = set()\n", + "dam_from = set()# Stores names of pokemon which have double damage from the type.\n", "\n", "#getting json from webpage\n", "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n", "res = requests.get(url)\n", "obj = res.json()\n", - "\n", + "c=0\n", "#running elements of obj\n", "for w in obj['types']:\n", "\n", " link = w['type']['url'] \n", " r = requests.get(link)\n", - " a = r.json()\n", + " a = r.json()# get json of type detail\n", "\n", - " link1 = a['damage_relations']['double_damage_to'][1]['url']\n", + " #print pokemon type which has double damage from\n", + " print(a['damage_relations']['double_damage_from'][c]['name'])\n", + " print('-------')\n", + " c+=1\n", + "\n", + " #Get tink to get list of pokemon in the above type\n", + " link1 = a['damage_relations']['double_damage_from'][1]['url']\n", " res1 = requests.get(link1)\n", " b = res1.json()\n", - "\n", + " \n", + " #printing the pokemon names of the above printed type\n", " for i in range(5):\n", " print(b['pokemon'][i]['pokemon']['name'])\n", - "\n", - " break\n" + " print('\\n')\n", + "\n" ] }, { @@ -637,7 +682,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -651,7 +696,7 @@ "\n", "test_abilities.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n", "\n", - "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 1.78s\u001b[0m\u001b[32m ===============================\u001b[0m\n" + "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 1.84s\u001b[0m\u001b[32m ===============================\u001b[0m\n" ] } ], From 7b9177ccf586c498838d36f322b1cca92abf1c47 Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 20:41:44 +0530 Subject: [PATCH 11/12] Update nearest_square.py --- nearest_square.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nearest_square.py b/nearest_square.py index d9d252d..5c58d0f 100644 --- a/nearest_square.py +++ b/nearest_square.py @@ -1,8 +1,14 @@ import math def nearest_square(n): - + + #If n is positive the square of integral part of square root will give the answer if n>0: i=int(math.sqrt(n)) return (i*i) + + # If n negative then the closest solution will be zero else: return 0 + +nearest_square.__doc__ = """ + This function finds the nearest perfect square number which is less than or equal to the number. """ From 4fa9cf504915a1be215b365318273d174d6316bd Mon Sep 17 00:00:00 2001 From: siddharth424 Date: Sun, 10 Jan 2021 20:42:49 +0530 Subject: [PATCH 12/12] Update abiliy.py --- ability.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ability.py b/ability.py index 74b4c8d..797311d 100644 --- a/ability.py +++ b/ability.py @@ -13,3 +13,6 @@ def ability(pokemon): abilities.append(i['ability']['name']) return abilities +ability.__doc__ = """ + This function returns Abilities of a pokemon. """ +