From 94706e3d217a6d5f1d670e97806603623c427df1 Mon Sep 17 00:00:00 2001 From: s0mnaths Date: Sun, 10 Jan 2021 20:41:29 +0530 Subject: [PATCH 1/4] Complete ALl Challenges --- Python-ifed.ipynb | 358 ++++++++++++++++-- __pycache__/ability.cpython-38.pyc | Bin 0 -> 522 bytes __pycache__/nearest_square.cpython-38.pyc | Bin 0 -> 338 bytes __pycache__/pokedexFunc.cpython-38.pyc | Bin 0 -> 2353 bytes ...test_abilities.cpython-38-pytest-6.2.1.pyc | Bin 0 -> 1997 bytes ...nearest_square.cpython-38-pytest-6.2.1.pyc | Bin 0 -> 2043 bytes ability.py | 11 + nearest_square.py | 7 + pokedex.py | 34 ++ pokedexFunc.py | 91 +++++ step_4.py | 126 ++++++ 11 files changed, 590 insertions(+), 37 deletions(-) create mode 100644 __pycache__/ability.cpython-38.pyc create mode 100644 __pycache__/nearest_square.cpython-38.pyc create mode 100644 __pycache__/pokedexFunc.cpython-38.pyc create mode 100644 __pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc create mode 100644 __pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc create mode 100644 ability.py create mode 100644 nearest_square.py create mode 100644 pokedex.py create mode 100644 pokedexFunc.py create mode 100644 step_4.py diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..67eef5d 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -62,15 +62,16 @@ "### Describe what each of the following means\n", "\n", "#### Production\n", - "(Insert answer here)\n", + "It's the software running on production servers to handle live users and data of the intended audience.\n", + "\n", "#### Clean \n", - "(Insert answer here)\n", + "Clean means that the code should be simple, readable and consise, so that it's easy to read, write and maintain.\n", "#### Modular\n", - "(Insert answer here)\n", + "Modular means a design approach that subdivides a system into smaller parts that can be independently created and then used in different systems, example functions. It makes our code more organized, efficient, and reusable.\n", "#### Module\n", - "(Insert answer here)\n", + "Modules allow code to be reused by encapsulating them into files that can be imported into other files.\n", "#### Refactoring code\n", - "(Insert answer here)" + "Refactoring is a way to restructure your code to improve its internal structure without changing its external function at all. " ] }, { @@ -93,9 +94,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 +164,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 +240,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 +318,63 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "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": 5 + } + ], "source": [ - "# Insert your solution here" + "for i in range(len(df.columns)):\n", + " df.rename(columns={df.columns[i]: df.columns[i].replace(' ','_')}, inplace=True)\n", + "df.head()" ] }, { @@ -208,7 +411,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -219,7 +422,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -233,9 +436,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 8.520490884780884 seconds\n" + ] + } + ], "source": [ "start = time.time()\n", "verified_elements = []\n", @@ -257,11 +468,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 0.026564359664916992 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start = time.time()\n", + "subsetArr=np.array(subset_elements)\n", + "allArr=np.array(all_elements)\n", + "verified_elements = np.array([])\n", + "\n", + "verified_elements=np.intersect1d(subsetArr,allArr)\n", "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" @@ -276,14 +500,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 0.006795406341552734 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start = time.time()\n", + "verified_elements = list(set(subset_elements)&set(all_elements))\n", "\n", "print(len(verified_elements))\n", - "print('Duration: {} seconds'.format(time.time() - start))" + "print(f'Duration: {time.time() - start} seconds')" ] }, { @@ -330,9 +563,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "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/somubuntu/Desktop/Python-ifed-challenge-pvt\nplugins: xonsh-0.9.13\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" ] @@ -386,11 +627,27 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Discord channel name: Pikachu\nPokekon Type: ELECTRIC\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests,json\n", + "\n", + "response=requests.get(\"https://pokeapi.co/api/v2/pokemon/pikachu\")\n", + "response.raise_for_status()\n", + "pikachuData=response.json()\n", + "typeData=pikachuData['types'][0]\n", + "typeName=typeData['type']['name']\n", + "print(\"Discord channel name: Pikachu\")\n", + "print(\"Pokekon Type: \",typeName.upper())" ] }, { @@ -404,11 +661,25 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Takes damage from: GROUND & FLYING types.\n" + ] + } + ], "source": [ - "# Insert your code here" + "typeURL=typeData['type']['url']\n", + "response=requests.get(typeURL)\n", + "pikachuData=response.json()\n", + "damageData=pikachuData['damage_relations']\n", + "double_damage_from=damageData['double_damage_from'][0]['name']\n", + "half_damage_from=damageData['half_damage_from'][0]['name']\n", + "print(f'Takes damage from: {double_damage_from.upper()} & {half_damage_from.upper()} types.')" ] }, { @@ -420,11 +691,24 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "sandshrew\nsandslash\nnidoqueen\nnidoking\ndiglett\n" + ] + } + ], "source": [ - "# Insert your code here" + "response=requests.get(\"https://pokeapi.co/api/v2/type/\"+double_damage_from)\n", + "response.raise_for_status()\n", + "typeData=response.json()\n", + "pikachuData=typeData['pokemon']\n", + "for i in range(5):\n", + " print(pikachuData[i]['pokemon']['name'])" ] }, { @@ -515,7 +799,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 0000000000000000000000000000000000000000..2427a614f97cd43ea50b8e1ed224c699c81d3ac4 GIT binary patch literal 522 zcmYjOy-ve05I!ePDO5!r5U3IpTZh&XBSHv?P7Ds`SCrS5@hH67Z06lRC9_TK#&B&UnU_Dp77rw z^aQzw0sX=Zn9Q-uPFiRMs5hwQ7Qw=X2vWicY)M5*vhlV+0NLL{<&~cB`cU~xsA%br z;qkZ%O1hzCApAZE+Q%va&!dv!ykPQr7Fny!1!G#RB-in1t{4(~Id3AV%2>V6XK@nS zSekn8*Id^$K4~pW@69^+iuVV zi(RSFDl;7TKu{0~IG`m~d zNM*x#A;oYW@g$MiQV#WtWq*$z>2=e|bu&E#Acv&g9Ex~En%jY&yM5<-4qR$8_8)XG TR<|!xC5l8|xxX^*kv;DRq=tY~ literal 0 HcmV?d00001 diff --git a/__pycache__/nearest_square.cpython-38.pyc b/__pycache__/nearest_square.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d07011d1c95bd5f3eb8403bc15c7fdb66e0f71ee GIT binary patch literal 338 zcmY*UO-sW-5S>ZdT1qQDi1-(BNCTclg!Wv7;-w%Zc2`r9Y?A#D3h7Dzfxp7Pl&dGt z-g@$-MW{2pnKv^#Z<&YDXh1OUa=-dO{%VU;^HAIYW{4n2@H;I@cnb>rHKX-sK1hox zV6G8ryiGfLV!_^cMvqrJuHhG`Q`X}n-+9%zhMHg~dh>5AQov1D$Ld7}e#5Ha&9bLt ztQXZM=`QB`X_OSXj7*WcC#S57X40g#D5LwWO$rrmo}~!aNt|U8Dq;C*qgFr~yE2sn unUve+{C}&x5J^3XkB@vGed$;AdX2#K^q-5~e=Z@P z@L~R{z{4}R)k7#a;WQ-OvZh_iE8O}>x)pA72WpE~`3lrFclj#R4yP|kv-TNAl7l|Q zYH~SH+i?F5x7vY1lQYU`PBzFn9n+kiRn7?|P+R9@T*)iEvPrnLNyb)gaU0qWwC&sm z|JC<@cZAMltUNsuo<2>5mkhi#ITle8dnr>&a4(2GCWl!hVy$X553U!xo!#eqhkKou zJLb7HyUa5>IAD?Rc08qJ5D$$NM;a?kfzwT&$Npb*z)re{rfuN!$tsg17o37KS1oidK4}P3T;_+t1?uR(e{_j(bo= z7;ZyB*4C&CzuWMWci{PYcDAASDt4yK7+!#zMP}G0Y}hyx4uF{A?s7B+N{Qck(~_87xq`(i8XUQX?ORx2&bzhJBT^>sp%w8eiw3lc zIxeMcR@{z;KZ8jb<(jb4pmH5-Uy*`S;_OCcI?%X^ltq;pTSHJ5ZFB1bZIeGAjGf#* zb8;&O#W5-b>T^yhd9!WQ$6?Dsd+0`Bj)jAW+M3{AL7p=0o0v?e4BjSpJMzC_$*sfdJ=CNkidC2I^2$ zS(=KNH>)K9297$uWC*b!&VmMuVAL+5c;v&o3Tc@th)ZqIke{gB1l#p&`~kf;XCt?O zi~EKPJ9qF@LUl1rY?VyB|94(mra-WxAPjT>n)3D8@qZpsHxiSQf?0SAEbNA%H|vDh zr&_U;bo{eWtX{rbtdz~uGWE_?sh1lt1`>|n@|+sfFP#`cc!0h5%`YV1*!ID`ly#S` tQ_~B+jr5@En8U>AgaKmFqfs0qHtypn;aMo2;GYzQoHi=%kM6p=@daiPK=c3r literal 0 HcmV?d00001 diff --git a/__pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc b/__pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8a44c6f3e11db3c1cf3328273f4a97db3d3092b5 GIT binary patch literal 1997 zcmds2OOF#d5Vrf3P9`%Fj~(DP7bNQBmIH5~1Vo5LYLJxGCJO7ff!Cmgb?DGcqVQ%s!Z^7K+ z^f3uGKEQtDVL;0U>%}rQ<32h*KOQIz7G3@1E$S_9$EYQ3p&|5e<2@V33Ti4rLwcXgW6u8FW`JB&_QdqvtN6!2U=l17EWlx z8WfjMTtRXDXp3nrl&Lnj8R!z6Hy6$7jk0wo9~+@f#8i1A>N6=LC34lzlAI|~wjmt# ziddRB)ukshSfR_aksf7*D6<}uQOXigHY3dj0(U64{;W=ov-F-)nJQ03gG?pN zMB+s*S;`DV7GAi4C)5|bxN2NpHLk51S8Jo*?M7H#u{JL5Er>b=KpfrejJ#MUlB*u- zU*&3J$yJ{>e}Jnk;A$Qp09%XD(*`otpKQu_I5KIR4m&F23Q7JRtEIX^JQrf(t0L{NLpBcEjI-Pcu z?pg~t3$b9M^gs7Zg^SB`QQc*C>qZBiZ&!&!6&vW7$F8!m^eO!E)`f)~MPU&rOq;^p gS857dovI4Uzm;UXkm5Fcs)@!keR7htE#Jo9C(6Cz`Tzg` literal 0 HcmV?d00001 diff --git a/__pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc b/__pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2e231ecfab3834b01c69517a19b283baf3b3142f GIT binary patch literal 2043 zcmd6o&2QT_6u?P}l4U#bwr)$)4-5u|0o5UKoF+>GG((1ULs1MtfuTM4A}FEU7}3{A zd7Crovi8_h&ppIP@9)`3*PZ+)G^f5t*@4o!8@khE@bU3IilpBA@%i!ca)ZEg@2}Uc zLkamC2i1qc-~gI>2tp7+1Ja|qXQ9CeB_Z#b6g@1kLaS$iZV3LI^lHKs7WB5L2^;#l zsEY>l4MBe*PIC(Dkwb?Tt;qMJuToe2JOt$!?eoV1r3URgXzCnt|AaJFh$m2LnAhg92xZR`SAV>$1Dy$%e8LC)y)k!=I zgr4d?4dNp&a3e4Di@K}4zK<&ut#9?NgE;zL%2*bky8T#&Uh4Y4C4m=tDR?GU(Zn6f z19q!}yVb$hy~?!ha!{_e+tWuZ2i=VckvAa_7Y{loap-qc91f3$Q9A70_tj|{C!I&5 z^dyef27ObasL79#2Ny4Y`ba)#P=2V-?@15U^Dp?8qCJ?h=E&D@=4X5v8~V zGmGnsG8%O^@$1xQATX!a+gber>{qh-&y@yp`c9?6JW|N&ywdQ0sWe>YZ&9T&XO+eh zwGXH?_Tf|~06$bBkh%m&8?`11ooNibTtR_1sS>w^H(?LgdEZTFgYN@k_CKx8h~V^N z5Ssu05V(~^z-`{eT)Z!GUxLqR7WTaKO5DG=;g-dEy}U9|K-Z=Js~n_IcrQ&wZDx}# rJTv|;=#nInVA)22t5>qC^Q^CieJ_l~Fz~;@>#h(7n_MGH%+|j*crxaM literal 0 HcmV?d00001 diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..ad5215a --- /dev/null +++ b/ability.py @@ -0,0 +1,11 @@ +import requests,json + +def ability(pokeName): + response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName) + response.raise_for_status() + pikachuData=response.json() + abilitiesData=pikachuData['abilities'] + abilities=[] + for ability in abilitiesData: + abilities.append(ability['ability']['name']) + return abilities diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..0f8ba6f --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,7 @@ +def nearest_square(n): + if n>0: + for i in range(n): + if i*i <= n: + nearSq = i*i + return nearSq + return 0 diff --git a/pokedex.py b/pokedex.py new file mode 100644 index 0000000..9dbbb73 --- /dev/null +++ b/pokedex.py @@ -0,0 +1,34 @@ +import PySimpleGUI as sg +from pokedexFunc import pokeType,ability,TypeDoubleDmg,DoubleDmg5 + +sg.theme('DarkBlue') +layout = [[sg.Text("Enter Pokemon Name: ")], + [sg.Input(size=(35,1),key='-INPUT-')], + [sg.Text(size=(35,3), key='-Type-')], + [sg.Text(size=(35,2), key='-DDF-')], + [sg.Text(size=(35,7), key='-DDP-')], + [sg.Text(size=(35,8), key='-ABILITIES-')], + [sg.Button('Get Details'), sg.Button('Quit')]] + +window = sg.Window('POKEDEX', layout, alpha_channel=0.95) + +while True: + event, values = window.read() + + if event == sg.WINDOW_CLOSED or event == 'Quit': + break + + typeName=pokeType(values['-INPUT-'].lower()) + double_damage_from=TypeDoubleDmg(typeName) + DoubleDamagePoksList=DoubleDmg5(double_damage_from) + doubleDamagePoks='\n--> '.join([str(i).upper() for i in DoubleDamagePoksList]) + abilitiesList=ability(values['-INPUT-'].lower()) + abilities='\n--> '.join([str(i).upper() for i in abilitiesList]) + + window['-Type-'].update('\nType: '+typeName.upper()) + window['-DDF-'].update('Double Damage from type: '+double_damage_from.upper()) + window['-DDP-'].update(f'Double Damage from pokemons:\n--> {doubleDamagePoks}') + window['-ABILITIES-'].update(f'Abilities:\n--> {abilities}') + + +window.close() \ No newline at end of file diff --git a/pokedexFunc.py b/pokedexFunc.py new file mode 100644 index 0000000..eeb0128 --- /dev/null +++ b/pokedexFunc.py @@ -0,0 +1,91 @@ +#! python3 +# pokedexFunc.py + +import requests,json + +def pokeType(pokeName): + '''Returns the type of pokemon passed in arguments + + PARAMETERS: + ----------- + pokeName : string + Name of the pokemon + + RETURNS: + ---------- + typeName : string + Type of the pokemon + ''' + + response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName) + response.raise_for_status() + pikachuData=response.json() + typeData=pikachuData['types'][0] + typeName=typeData['type']['name'] + return typeName + +def TypeDoubleDmg(typeName): + '''Returns the pokemon type which gives 2x damage to the type passed in arguments + + PARAMETERS: + ----------- + typeName : string + Type of pokemon + + RETURNS: + ----------- + double_damage_from: string + Type of pokemon which gives 2x damage to pokeName + ''' + + response=requests.get("https://pokeapi.co/api/v2/type/"+typeName) + pikachuData=response.json() + damageData=pikachuData['damage_relations'] + double_damage_from=damageData['double_damage_from'][0]['name'] + return double_damage_from + +def DoubleDmg5(double_damage_from): + '''Returns the list of five pokemons of the type passed in arguments + + PARAMETERS: + ----------- + double_damage_from : string + Type of pokemon + + RETURNS: + ------------ + DDF : list + Names of five pokemon of type double_damage_from, in a list + ''' + + response=requests.get("https://pokeapi.co/api/v2/type/"+double_damage_from) + response.raise_for_status() + typeData=response.json() + pikachuData=typeData['pokemon'] + DDF=[] + for i in range(5): + DDF.append(pikachuData[i]['pokemon']['name']) + return DDF + +def ability(pokeName): + '''Returns the list of abilities of the pokemon passed in arguments + + PARAMETERS: + ----------- + pokeName : string + Name of pokemon + + RETURNS: + ------------ + abilities : list + All abilities of pokeName, in a list + ''' + + response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName) + response.raise_for_status() + pikachuData=response.json() + abilitiesData=pikachuData['abilities'] + abilities=[] + for ability in abilitiesData: + abilities.append(ability['ability']['name']) + return abilities \ No newline at end of file diff --git a/step_4.py b/step_4.py new file mode 100644 index 0000000..fb4590a --- /dev/null +++ b/step_4.py @@ -0,0 +1,126 @@ +#! python3 +# step_4.py +""" STEP-4 +This script was made for learning how to optimize our python code. + +It reads data from two .txt files, and prints the +number of lines which are same in both the .txt files. + +This script requires that `pandas` be installed within the Python +environment you are running this script in. +""" + +import time +import pandas as pd +import numpy as np + +def openFiles(): + """Open two text files and stores each line in the of that file in a list + Parameters: + -------------- + None + + Returns: + ------------- + subset_elements : list + a list of strings from subset_elemets.txt + all_elements : list + a list of strings from subset_elements.txt + """ + + with open('subset_elemets.txt') as f: + subset_elements = f.read().split('\n') + + with open('all_elements.txt') as f: + all_elements = f.read().split('\n') + return subset_elements,all_elements + +def appendOldWay(subset_elements,all_elements): + """Prints a list of elements and time taken to execute this function. + + This function uses nested for loops and append() method to find the elements + which are present in both the lists passed as arguments, and stores them in a + new list. It prints the length of the new list along with time taken by this + function. + + Parameters: + -------------- + subset_elements : list + a list of strings + all_elements : list + a list of strings + Returns: + ------------- + None + """ + 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 appendNumPy(subset_elements, all_elements): + """Prints a list of elements and time taken to execute this function. + + This function uses NumPy methods to find the elements which are present + in both the lists passed as arguments, and stores them in a new list. + It prints the length of the new list along with time taken by this + function. + + Parameters: + -------------- + subset_elements : list + a list of strings + all_elements : list + a list of strings + Returns: + ------------- + None + """ + + start = time.time() + subsetArr=np.array(subset_elements) + allArr=np.array(all_elements) + verified_elements = np.array([]) + verified_elements=np.intersect1d(subsetArr,allArr) + print(len(verified_elements)) + print('Duration: {} seconds'.format(time.time() - start)) + +def appendDataStruct(subset_elements,all_elements): + """Prints a list of elements and time taken to execute this function. + + This function use of python data structures and set() method to find + the elements which are present in both the lists passed as arguments, + and stores them in a new list. It prints the length of the new list along + with time taken by this + function. + + Parameters: + -------------- + subset_elements : list + a list of strings + all_elements : list + a list of strings + Returns: + ------------- + None + """ + + start = time.time() + verified_elements = list(set(subset_elements)&set(all_elements)) + print(len(verified_elements)) + print(f'Duration: {time.time() - start} seconds') + +def main(): + subset_elements, all_elements=openFiles() + print('When Using old code with for loop--->') + appendOldWay(subset_elements,all_elements) + print("when using NumPy module's methods--->") + appendNumPy(subset_elements,all_elements) + print("When using python data structure's methods(sets)--->") + appendDataStruct(subset_elements,all_elements) + +if __name__=="__main__": + main() \ No newline at end of file From 2c2b1c0b6d0ed3c74e76e1883ada353918182ce9 Mon Sep 17 00:00:00 2001 From: s0mnaths Date: Sun, 10 Jan 2021 20:44:47 +0530 Subject: [PATCH 2/4] Complete all Challenges --- Python-ifed.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 67eef5d..a985997 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -65,7 +65,7 @@ "It's the software running on production servers to handle live users and data of the intended audience.\n", "\n", "#### Clean \n", - "Clean means that the code should be simple, readable and consise, so that it's easy to read, write and maintain.\n", + "Clean means that the code should be simple, readable and consise, so that it's easy to read, write and maintain.\n", "#### Modular\n", "Modular means a design approach that subdivides a system into smaller parts that can be independently created and then used in different systems, example functions. It makes our code more organized, efficient, and reusable.\n", "#### Module\n", From f0e62b9c82d16b4acbec11fa4ed7cc5d4791abe0 Mon Sep 17 00:00:00 2001 From: Somnath Sharma <73424897+s0mnaths@users.noreply.github.com> Date: Sun, 10 Jan 2021 20:46:02 +0530 Subject: [PATCH 3/4] Delete Python-ifed.ipynb --- Python-ifed.ipynb | 807 ---------------------------------------------- 1 file changed, 807 deletions(-) delete mode 100644 Python-ifed.ipynb diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb deleted file mode 100644 index a985997..0000000 --- a/Python-ifed.ipynb +++ /dev/null @@ -1,807 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Python-ifed\n", - "\n", - "Welcome to the python-ifed notebook, This notebook is a walkthrough + task for you to get started with software development using python.\n", - "\n", - "After completing this notebook successfully you should be familiar with the following concepts:\n", - "* Use version control\n", - "* Writing clean and modular code\n", - "* Improve code efficiency\n", - "* Add effective documentation\n", - "* Testing \n", - "* Code reviews\n", - "\n", - "**This exercise depends on a lot of googling skills and is aimed at making you efficient in the same**." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 1 : Tables and stuff" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 0\n", - "\n", - "You might be already done with this step\n", - "\n", - "### Learn to version control using git\n", - "\n", - "1. Install git CLI tool\n", - "1. Configure git CLI\n", - "1. Create a GitHub account if you already have not \n", - "1. Clone the repo that contains this repository\n", - "1. Now you are in master branch\n", - "1. Create a new branch with your name as the branch name and continue\n", - "\n", - "### Reference materials\n", - "https://www.atlassian.com/git\n", - "\n", - "https://www.tutorialspoint.com/git/git_basic_concepts.htm" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Step 1\n", - "\n", - "## Clean and modular code\n", - "\n", - "Test out your googling skills and understand what writing clean and modular code means and answer the following questions by editing this cell in jupyter notebook.\n", - "\n", - "### Describe what each of the following means\n", - "\n", - "#### Production\n", - "It's the software running on production servers to handle live users and data of the intended audience.\n", - "\n", - "#### Clean \n", - "Clean means that the code should be simple, readable and consise, so that it's easy to read, write and maintain.\n", - "#### Modular\n", - "Modular means a design approach that subdivides a system into smaller parts that can be independently created and then used in different systems, example functions. It makes our code more organized, efficient, and reusable.\n", - "#### Module\n", - "Modules allow code to be reused by encapsulating them into files that can be imported into other files.\n", - "#### Refactoring code\n", - "Refactoring is a way to restructure your code to improve its internal structure without changing its external function at all. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If you have finished writing the answers you can now commit these new changes with git using the commit message __step 1 completed__ ." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Step 2\n", - "\n", - "## Refactor: Cricket Match Analysis\n", - "\n", - "Here I would be providing you with a sample code, don't worry about the working much try to get an abstract idea and complete the task" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "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", - "df.set_index('id',inplace=True)\n", - "df.drop('umpire3',axis=1,inplace=True)\n", - "df.head()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is how our data looks like right now we need to write efficient code to replaces the spaces with an underscore, the janky way of doing this is" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "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", - " 'toss winner': 'toss_winner',\n", - " 'dl applied': 'dl_applied',\n", - " 'win by runs': 'win_by_runs',\n", - " 'win by wickets': 'win_by_wickets',\n", - " 'player of match': 'player_of_match',\n", - " 'umpire 1':'umpire_1',\n", - " 'umpire 2':'umpire_2'\n", - " })\n", - "new_df.head()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is like a hardcoded way of doing it slightly better way of doing this is " - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "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", - "labels[1] = labels[1].replace(' ', '_')\n", - "labels[2] = labels[2].replace(' ', '_')\n", - "labels[3] = labels[3].replace(' ', '_')\n", - "labels[5] = labels[5].replace(' ', '_')\n", - "labels[6] = labels[6].replace(' ', '_')\n", - "labels[7] = labels[7].replace(' ', '_')\n", - "labels[8] = labels[8].replace(' ', '_')\n", - "labels[9] = labels[9].replace(' ', '_')\n", - "labels[10] = labels[10].replace(' ', '_')\n", - "df.columns = labels\n", - "df.head()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is also a very redundant way of doing this try writing a better code to do the same. Limit yourselves to one or two lines of code." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "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": 5 - } - ], - "source": [ - "for i in range(len(df.columns)):\n", - " df.rename(columns={df.columns[i]: df.columns[i].replace(' ','_')}, inplace=True)\n", - "df.head()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Once you are done till here make a new commit with message __step 2 complete__." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Step 3\n", - "\n", - "## Optimizing Code\n", - "\n", - "### Efficient Code\n", - "\n", - "Knowing how to write code that runs efficiently is another essential skill in software development. Optimizing code to be more efficient can mean making it:\n", - "\n", - "* Execute faster\n", - "* Take up less space in memory/storage\n", - "\n", - "\n", - "Resources:\n", - "https://stackify.com/20-simple-python-performance-tuning-tips/\n", - "\n", - "https://pybit.es/faster-python.html\n", - "\n", - "https://towardsdatascience.com/one-simple-trick-for-speeding-up-your-python-code-with-numpy-1afc846db418\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "import time\n", - "import pandas as pd\n", - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "with open('subset_elemets.txt') as f:\n", - " subset_elements = f.read().split('\\n')\n", - " \n", - "with open('all_elements.txt') as f:\n", - " all_elements = f.read().split('\\n')\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "96\nDuration: 8.520490884780884 seconds\n" - ] - } - ], - "source": [ - "start = time.time()\n", - "verified_elements = []\n", - "\n", - "for element in subset_elements:\n", - " if element in all_elements:\n", - " verified_elements.append(element)\n", - "\n", - "print(len(verified_elements))\n", - "print('Duration: {} seconds'.format(time.time() - start))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Use vector operations using NumPy to optimise the loop" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "96\nDuration: 0.026564359664916992 seconds\n" - ] - } - ], - "source": [ - "start = time.time()\n", - "subsetArr=np.array(subset_elements)\n", - "allArr=np.array(all_elements)\n", - "verified_elements = np.array([])\n", - "\n", - "verified_elements=np.intersect1d(subsetArr,allArr)\n", - "\n", - "print(len(verified_elements))\n", - "print('Duration: {} seconds'.format(time.time() - start))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Use a python datastructure which has a method to peform this task faster" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "96\nDuration: 0.006795406341552734 seconds\n" - ] - } - ], - "source": [ - "start = time.time()\n", - "verified_elements = list(set(subset_elements)&set(all_elements))\n", - "\n", - "print(len(verified_elements))\n", - "print(f'Duration: {time.time() - start} seconds')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Step 4\n", - "# Documentation\n", - "\n", - "Documentation is one of the important part of software development. Teach yourself about documentation in python and convert code in step 3 to functions and add relevant documentation for the same.\n", - "\n", - "#### Resources\n", - "https://www.python.org/dev/peps/pep-0257/\n", - "\n", - "https://numpydoc.readthedocs.io/en/latest/format.html\n", - "\n", - "https://www.datacamp.com/community/tutorials/documenting-python-code\n", - "\n", - "do not add this code to the notebook instead create a new python file called step_4.py and define the functions as well as a main to test the working of all the functions make sure to version this file as well on the commit message __step 4 completed__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Step 5\n", - "\n", - "# Testing\n", - "\n", - "Testing your code is essential before deployment. It helps you catch errors and faulty conclusions before they make any major impact. Today, employers are looking for data scientists with the skills to properly prepare their code for an industry setting, which includes testing their code.\n", - "\n", - "Learn about pytest and install it \n", - "\n", - "https://docs.pytest.org/en/stable/\n", - "\n", - "create a new file called nearest_square.py this function should return the nearest perfect square number which is less than or equal to the number.\n", - "\n", - "create another file called test_nearest_square.py to test the function with different test each for values 5,-12,9 and 23\n", - "\n", - "execute the line below to ensure it is working correctly\n", - "\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "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/somubuntu/Desktop/Python-ifed-challenge-pvt\nplugins: xonsh-0.9.13\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" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If you are done with this step make a new commit __step5 completed__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Step 6 \n", - "# Code review\n", - "\n", - "Understand how code review works\n", - "\n", - "https://github.com/lyst/MakingLyst/tree/master/code-reviews\n", - "\n", - "https://www.kevinlondon.com/2015/05/05/code-review-best-practices.html\n", - "\n", - "_Leave it to us_ if you are done with this step go ahead and push this notebook as well as all the files to your GitHub and make a pull request to the repository that you cloned this task from so that we can review your progress till now, Please continue with the challenge" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 2 : Pokemon" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now that you are familiar with writing efficient code let's use that practice and do some API fetching to answer some questions, Below are some questions below and you should use the [pokeapi](https://pokeapi.co/) to do some API fetching with python and answer the questions.\n", - "\n", - "**NOTE**\n", - "You should fill the cell with code that gives the answer and not write the answer directly, failing to do so will reduce your evaluation and proves that you did not bother reading this part." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Remember you were in a pokemon room (discord) what is the **type** of that pokemon" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Discord channel name: Pikachu\nPokekon Type: ELECTRIC\n" - ] - } - ], - "source": [ - "import requests,json\n", - "\n", - "response=requests.get(\"https://pokeapi.co/api/v2/pokemon/pikachu\")\n", - "response.raise_for_status()\n", - "pikachuData=response.json()\n", - "typeData=pikachuData['types'][0]\n", - "typeName=typeData['type']['name']\n", - "print(\"Discord channel name: Pikachu\")\n", - "print(\"Pokekon Type: \",typeName.upper())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "What **type** of pokemons does this **type** take damage from\n", - "\n", - "__hint__ the url field of previous response" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Takes damage from: GROUND & FLYING types.\n" - ] - } - ], - "source": [ - "typeURL=typeData['type']['url']\n", - "response=requests.get(typeURL)\n", - "pikachuData=response.json()\n", - "damageData=pikachuData['damage_relations']\n", - "double_damage_from=damageData['double_damage_from'][0]['name']\n", - "half_damage_from=damageData['half_damage_from'][0]['name']\n", - "print(f'Takes damage from: {double_damage_from.upper()} & {half_damage_from.upper()} types.')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For each of the **double damage from** type list 5 pokemons in that type" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "sandshrew\nsandslash\nnidoqueen\nnidoking\ndiglett\n" - ] - } - ], - "source": [ - "response=requests.get(\"https://pokeapi.co/api/v2/type/\"+double_damage_from)\n", - "response.raise_for_status()\n", - "typeData=response.json()\n", - "pikachuData=typeData['pokemon']\n", - "for i in range(5):\n", - " print(pikachuData[i]['pokemon']['name'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a function ability() inside a new file ability.py to return a list of the abilities of any given pokemon by doing an API query the function should accept a string parameter which is the name of the pokemon\n", - "\n", - "execute the line below to ensure everything is working properly" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "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" - ] - } - ], - "source": [ - "!pytest test_abilities.py" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Please version till this point saying with a message \"Completed challenge 2\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Extra Challenge for extra karma point" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If the above challenge was a cakewalk and you have a lot of time left to attempt this challenge to earn some karma points, this challenge is completely optional.\n", - "Let's create a pokedex with the function we created earlier on that is\n", - "\n", - "* What is the type of pokemon\n", - "* What type of pokemon gives double damages to the given pokemon\n", - "* List 5 pokemons which gives the given pokemon double damage\n", - "* Abilities of our pokemon\n", - "\n", - "Use [pysimplegui](https://pypi.org/project/PySimpleGUI) to create a simple pokedex which consumes these functions\n", - "\n", - "save the file as pokedex.py" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Version till this point with a message \"Completed Extra Challenge\"\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5-final" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} \ No newline at end of file From 999964d0e48afacbadacf07b424172a9fc5484f0 Mon Sep 17 00:00:00 2001 From: s0mnaths Date: Sun, 10 Jan 2021 20:48:53 +0530 Subject: [PATCH 4/4] Add Python-ifed.ipynb --- Python-ifed.ipynb | 358 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 321 insertions(+), 37 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..67eef5d 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -62,15 +62,16 @@ "### Describe what each of the following means\n", "\n", "#### Production\n", - "(Insert answer here)\n", + "It's the software running on production servers to handle live users and data of the intended audience.\n", + "\n", "#### Clean \n", - "(Insert answer here)\n", + "Clean means that the code should be simple, readable and consise, so that it's easy to read, write and maintain.\n", "#### Modular\n", - "(Insert answer here)\n", + "Modular means a design approach that subdivides a system into smaller parts that can be independently created and then used in different systems, example functions. It makes our code more organized, efficient, and reusable.\n", "#### Module\n", - "(Insert answer here)\n", + "Modules allow code to be reused by encapsulating them into files that can be imported into other files.\n", "#### Refactoring code\n", - "(Insert answer here)" + "Refactoring is a way to restructure your code to improve its internal structure without changing its external function at all. " ] }, { @@ -93,9 +94,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 +164,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 +240,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 +318,63 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "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": 5 + } + ], "source": [ - "# Insert your solution here" + "for i in range(len(df.columns)):\n", + " df.rename(columns={df.columns[i]: df.columns[i].replace(' ','_')}, inplace=True)\n", + "df.head()" ] }, { @@ -208,7 +411,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -219,7 +422,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -233,9 +436,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 8.520490884780884 seconds\n" + ] + } + ], "source": [ "start = time.time()\n", "verified_elements = []\n", @@ -257,11 +468,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 0.026564359664916992 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start = time.time()\n", + "subsetArr=np.array(subset_elements)\n", + "allArr=np.array(all_elements)\n", + "verified_elements = np.array([])\n", + "\n", + "verified_elements=np.intersect1d(subsetArr,allArr)\n", "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" @@ -276,14 +500,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "96\nDuration: 0.006795406341552734 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start = time.time()\n", + "verified_elements = list(set(subset_elements)&set(all_elements))\n", "\n", "print(len(verified_elements))\n", - "print('Duration: {} seconds'.format(time.time() - start))" + "print(f'Duration: {time.time() - start} seconds')" ] }, { @@ -330,9 +563,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "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/somubuntu/Desktop/Python-ifed-challenge-pvt\nplugins: xonsh-0.9.13\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" ] @@ -386,11 +627,27 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Discord channel name: Pikachu\nPokekon Type: ELECTRIC\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests,json\n", + "\n", + "response=requests.get(\"https://pokeapi.co/api/v2/pokemon/pikachu\")\n", + "response.raise_for_status()\n", + "pikachuData=response.json()\n", + "typeData=pikachuData['types'][0]\n", + "typeName=typeData['type']['name']\n", + "print(\"Discord channel name: Pikachu\")\n", + "print(\"Pokekon Type: \",typeName.upper())" ] }, { @@ -404,11 +661,25 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Takes damage from: GROUND & FLYING types.\n" + ] + } + ], "source": [ - "# Insert your code here" + "typeURL=typeData['type']['url']\n", + "response=requests.get(typeURL)\n", + "pikachuData=response.json()\n", + "damageData=pikachuData['damage_relations']\n", + "double_damage_from=damageData['double_damage_from'][0]['name']\n", + "half_damage_from=damageData['half_damage_from'][0]['name']\n", + "print(f'Takes damage from: {double_damage_from.upper()} & {half_damage_from.upper()} types.')" ] }, { @@ -420,11 +691,24 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "sandshrew\nsandslash\nnidoqueen\nnidoking\ndiglett\n" + ] + } + ], "source": [ - "# Insert your code here" + "response=requests.get(\"https://pokeapi.co/api/v2/type/\"+double_damage_from)\n", + "response.raise_for_status()\n", + "typeData=response.json()\n", + "pikachuData=typeData['pokemon']\n", + "for i in range(5):\n", + " print(pikachuData[i]['pokemon']['name'])" ] }, { @@ -515,7 +799,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.5-final" } }, "nbformat": 4,