diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..3ddea9e 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", + "The final code that is provided to the client or the public after multiple development and undergoing multiple test by the testers , is known as the production code. \n", "#### Clean \n", - "(Insert answer here)\n", + "A clean code is the code which is more visually appealing and understandable.A clean code is important as it facilitates several features which enables us to make easier maintainence, save time in the long run and also helps easier debugging.\n", "#### Modular\n", - "(Insert answer here)\n", + "The code which can be divided to several independent,interchangeable modules which are used to perform a part of the function of the entire code.\n", "#### Module\n", - "(Insert answer here)\n", + "The independent blocks of code which together forms a program is called a module.\n", "#### Refactoring code\n", - "(Insert answer here)" + "Refactoring code is the process of restructuring the existing code, that is changing the factor without making any changes to the logic of the code" ] }, { @@ -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", @@ -113,9 +163,59 @@ }, { "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": [ "new_df = df.rename(columns={'team 1': 'team_1',\n", " 'team 2': 'team_2',\n", @@ -139,9 +239,59 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "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": 4 + } + ], "source": [ "labels = list(df.columns)\n", "labels[0] = labels[0].replace(' ', '_')\n", @@ -167,11 +317,63 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "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": 7 + } + ], "source": [ - "# Insert your solution here" + "new_df=df\n", + "new_df.columns = df.columns.str.replace(' ','_')\n", + "new_df.head()" ] }, { @@ -208,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -219,11 +421,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "with open('subset_elemets.txt') as f:\n", + "with open('subset_elements.txt') as f:\n", " subset_elements = f.read().split('\\n')\n", " \n", "with open('all_elements.txt') as f:\n", @@ -233,9 +435,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 9.655861854553223 seconds\n" + ] + } + ], "source": [ "start = time.time()\n", "verified_elements = []\n", @@ -257,11 +467,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 0.026705026626586914 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start=time.time()\n", + "verified_elements = []\n", + "\n", + "verified_elements=np.intersect1d(subset_elements,all_elements)\n", "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" @@ -276,11 +497,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 0.009980916976928711 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start=time.time()\n", + "verified_elements = []\n", + "\n", + "verified_elements=list(set(all_elements)&set(subset_elements))\n", "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" @@ -330,9 +562,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "============================= test session starts =============================\n", + "platform win32 -- Python 3.8.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1\n", + "rootdir: c:\\Users\\gopil\\Desktop\\Python-ifed-challenge\n", + "collected 4 items\n", + "\n", + "test_nearest_square.py .... [100%]\n", + "\n", + "============================== 4 passed in 0.02s ==============================\n" + ] + } + ], "source": [ "! pytest test_nearest_square.py" ] @@ -386,11 +633,27 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Type 1: ghost\nType 2: poison\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests\n", + "\n", + "url = \"http://pokeapi.co/api/v2/pokemon/gengar/\"\n", + "\n", + "payload = \"\"\n", + "response = requests.request(\"GET\", url, data=payload)\n", + "data = response.json()\n", + "print(\"Type 1:\",data[\"types\"][0][\"type\"][\"name\"])\n", + "print(\"Type 2:\",data[\"types\"][1][\"type\"][\"name\"])" ] }, { @@ -404,11 +667,46 @@ }, { "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], + "execution_count": 26, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Damage for ghost type:\n\nghost\ndark\npoison\nbug\n\nDamage for poison type:\n\nground\npsychic\nfighting\npoison\nbug\ngrass\nfairy\n" + ] + } + ], "source": [ - "# Insert your code here" + "payload = \"\"\n", + "response = requests.request(\"GET\", url, data=payload)\n", + "\n", + "data = response.json()\n", + "url1=(data[\"types\"][0][\"type\"][\"url\"])\n", + "url2=(data[\"types\"][1][\"type\"][\"url\"])\n", + "payload1 = \"\"\n", + "payload2 = \"\"\n", + "response1 = requests.request(\"GET\", url1, data=payload1)\n", + "response2 = requests.request(\"GET\", url2, data=payload2)\n", + "data1 = response1.json()\n", + "data2 = response2.json()\n", + "print(\"Damage for ghost type:\\n\")\n", + "\n", + "for i in range(len(data1[\"damage_relations\"][\"double_damage_from\"])):\n", + " print(data1[\"damage_relations\"][\"double_damage_from\"][i][\"name\"])\n", + " \n", + "for i in range(len(data1[\"damage_relations\"][\"half_damage_from\"])):\n", + " print(data1[\"damage_relations\"][\"half_damage_from\"][i][\"name\"])\n", + "print(\"\\nDamage for poison type:\\n\")\n", + "\n", + "for i in range(len(data2[\"damage_relations\"][\"double_damage_from\"])):\n", + " print(data2[\"damage_relations\"][\"double_damage_from\"][i][\"name\"])\n", + "\n", + "for i in range(len(data2[\"damage_relations\"][\"half_damage_from\"])):\n", + " print(data2[\"damage_relations\"][\"half_damage_from\"][i][\"name\"])" ] }, { @@ -420,11 +718,59 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "gastly,haunter,gengar,misdreavus,shedinja,\n", + "\n", + "umbreon,murkrow,sneasel,houndour,houndoom,\n", + "\n", + "sandshrew,sandslash,nidoqueen,nidoking,diglett,\n", + "\n", + "abra,kadabra,alakazam,slowpoke,slowbro,\n", + "\n" + ] + } + ], "source": [ - "# Insert your code here" + "payload = \"\"\n", + "response = requests.request(\"GET\", url, data=payload)\n", + "\n", + "data = response.json()\n", + "\n", + "url1=(data[\"types\"][0][\"type\"][\"url\"])\n", + "url2=(data[\"types\"][1][\"type\"][\"url\"])\n", + "\n", + "payload=\"\"\n", + "payload1 = \"\"\n", + "payload2 = \"\"\n", + "\n", + "response = requests.request(\"GET\", url, data=payload)\n", + "response1 = requests.request(\"GET\", url1, data=payload1)\n", + "response2 = requests.request(\"GET\", url2, data=payload2)\n", + "\n", + "pokedata = response.json()\n", + "data1 = response1.json()\n", + "data2 = response2.json()\n", + "damage=[]\n", + "\n", + "\n", + "for i in range(len(data1[\"damage_relations\"][\"double_damage_from\"])):\n", + " damage.append(data1[\"damage_relations\"][\"double_damage_from\"][i][\"url\"])\n", + "\n", + "\n", + "for i in range(len(data2[\"damage_relations\"][\"double_damage_from\"])):\n", + " damage.append(data2[\"damage_relations\"][\"double_damage_from\"][i][\"url\"])\n", + "\n", + "for i in range(len(damage)):\n", + " pokedata = requests.request(\"GET\", damage[i], data=payload).json()\n", + " for j in range(5):\n", + " print(pokedata[\"pokemon\"][j][\"pokemon\"][\"name\"],end=',')\n", + " print(\"\\n\")" ] }, { @@ -438,21 +784,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 12, "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", - "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" + "============================= test session starts =============================\nplatform win32 -- Python 3.8.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1\nrootdir: c:\\Users\\gopil\\Desktop\\Python-ifed-challenge\ncollected 4 items\n\ntest_abilities.py .... [100%]\n\n============================== 4 passed in 1.51s ==============================\n" ] } ], @@ -515,7 +854,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.5-final" } }, "nbformat": 4, diff --git a/__pycache__/ability.cpython-38.pyc b/__pycache__/ability.cpython-38.pyc new file mode 100644 index 0000000..d806924 Binary files /dev/null and b/__pycache__/ability.cpython-38.pyc differ diff --git a/__pycache__/ability.cpython-39.pyc b/__pycache__/ability.cpython-39.pyc new file mode 100644 index 0000000..a03ea6f Binary files /dev/null and b/__pycache__/ability.cpython-39.pyc differ diff --git a/__pycache__/nearest_square.cpython-38.pyc b/__pycache__/nearest_square.cpython-38.pyc new file mode 100644 index 0000000..f4810b6 Binary files /dev/null and b/__pycache__/nearest_square.cpython-38.pyc differ diff --git a/__pycache__/test_abilities.cpython-38-pytest-6.1.1.pyc b/__pycache__/test_abilities.cpython-38-pytest-6.1.1.pyc new file mode 100644 index 0000000..69b4f57 Binary files /dev/null and b/__pycache__/test_abilities.cpython-38-pytest-6.1.1.pyc differ diff --git a/__pycache__/test_abilities.cpython-39-pytest-6.2.1.pyc b/__pycache__/test_abilities.cpython-39-pytest-6.2.1.pyc new file mode 100644 index 0000000..231cf16 Binary files /dev/null and b/__pycache__/test_abilities.cpython-39-pytest-6.2.1.pyc differ diff --git a/__pycache__/test_nearest_square.cpython-38-pytest-6.1.1.pyc b/__pycache__/test_nearest_square.cpython-38-pytest-6.1.1.pyc new file mode 100644 index 0000000..02fecc2 Binary files /dev/null and b/__pycache__/test_nearest_square.cpython-38-pytest-6.1.1.pyc differ diff --git a/__pycache__/test_nearest_square.cpython-39-pytest-6.2.1.pyc b/__pycache__/test_nearest_square.cpython-39-pytest-6.2.1.pyc new file mode 100644 index 0000000..5e160c5 Binary files /dev/null and b/__pycache__/test_nearest_square.cpython-39-pytest-6.2.1.pyc differ diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..9c1e5ba --- /dev/null +++ b/ability.py @@ -0,0 +1,9 @@ +import requests +def ability(name): + url = "http://pokeapi.co/api/v2/pokemon/"+name+"/" + data = requests.get(url).json() + abilitly=[] + for i in data["abilities"]: + abilitly.append(i['ability']['name']) + return abilitly + \ No newline at end of file diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..b1ecaa2 --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,7 @@ +import math + +def nearest_square(n): + if(n<=0): + return 0 + else: + return(math.floor(n**0.5)**2) \ No newline at end of file diff --git a/step_4.py b/step_4.py new file mode 100644 index 0000000..c7b1c85 --- /dev/null +++ b/step_4.py @@ -0,0 +1,56 @@ +import time +import numpy as np + + +def func1(all_elements, subset_elements): + """Description:The default way to find the intersection of two sets + """ + start = time.time() + verified_elements = [] + for element in subset_elements: + if element in all_elements: + verified_elements.append(element) + + print(len(verified_elements)) + print('Duration: {} seconds'.format(time.time() - start)) + + +def func2(all_elements, subset_elements): + """Description:The method of finding intersection of two sets using built-in function of numpy-intersect1d + """ + start = time.time() + verified_elements = np.intersect1d(np.array(subset_elements), np.array(all_elements)) + + print(len(verified_elements)) + print('Duration: {} seconds'.format(time.time() - start)) + + +def func3(all_elements, subset_elements): + """Description:The method of finding intersection of two sets using set data structure of Python + """ + start = time.time() + verified_elements = set(subset_elements) & set(all_elements) + + print(len(verified_elements)) + print('Duration: {} seconds'.format(time.time() - start)) + + +with open('subset_elements.txt') as f: + subset_elements = f.read().split('\n') + +with open('all_elements.txt') as f: + all_elements = f.read().split('\n') + + +def main(): + print(func1.__doc__) + func1(all_elements, subset_elements) + + print(func2.__doc__) + func2(all_elements, subset_elements) + + print(func3.__doc__) + func3(all_elements, subset_elements) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/subset_elemets.txt b/subset_elements.txt similarity index 100% rename from subset_elemets.txt rename to subset_elements.txt diff --git a/tempCodeRunnerFile.py b/tempCodeRunnerFile.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tempCodeRunnerFile.py @@ -0,0 +1 @@ +