diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..c3b38f8 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", + "A production system is a computer program typically used to provide some form of artificial intelligence, which consists primarily of a set of rules about behavior but it also includes the mechanism necessary to follow those rules as the system responds to states of the world.\n", "#### Clean \n", - "(Insert answer here)\n", + "A reader-focused development style that produces software that's easy to write, read, and maintain. Clean code is code that is easy to understand and easy to change. This means the code is easy to read, whether that reader is the original author of the code or somebody else.\n", "#### Modular\n", - "(Insert answer here)\n", + "Modular code is code which is separated into independent modules. The idea is that internal details of individual modules should be hidden behind a public interface, making each module easier to understand, test and refactor independently of others.\n", "#### Module\n", - "(Insert answer here)\n", + "A module is a piece of software that has a specific functionality. Each module is a different file, which can be edited separately.\n", "#### Refactoring code\n", - "(Insert answer here)" + "Code refactoring is defined as the process of restructuring computer code without changing or adding to its external behavior and functionality" ] }, { @@ -93,9 +93,214 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "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", + "
" + ], + "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 " + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import pandas as pd\n", "df = pd.read_csv('matches.csv', sep=',')\n", @@ -113,9 +318,214 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "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", + "
" + ], + "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 " + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "new_df = df.rename(columns={'team 1': 'team_1',\n", " 'team 2': 'team_2',\n", @@ -139,9 +549,214 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "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", + "
" + ], + "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 " + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "labels = list(df.columns)\n", "labels[0] = labels[0].replace(' ', '_')\n", @@ -167,11 +782,223 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "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", + "
" + ], + "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 " + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Insert your solution here" + "# Insert your solution here\n", + "labels = list(df.columns)\n", + "underscore_labels = list()\n", + "for label in labels:\n", + " label = label.replace(' ', '_')\n", + " underscore_labels.append(label)\n", + "df.columns = underscore_labels\n", + "df.head()" ] }, { @@ -208,7 +1035,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -219,7 +1046,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -233,9 +1060,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 10.741117238998413 seconds\n" + ] + } + ], "source": [ "start = time.time()\n", "verified_elements = []\n", @@ -257,11 +1093,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 0.024973392486572266 seconds\n" + ] + } + ], "source": [ "# Insert answer here\n", + "start = time.time()\n", + "verified_elements = np.intersect1d(subset_elements, all_elements) \n", "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" @@ -276,11 +1123,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 0.003989219665527344 seconds\n" + ] + } + ], "source": [ "# Insert answer here\n", + "start = time.time()\n", + "verified_elements = set(subset_elements).intersection(all_elements)\n", "\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" @@ -330,9 +1188,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "============================= test session starts =============================\n", + "platform win32 -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1\n", + "rootdir: C:\\Users\\91910\\Untitled Folder 1\n", + "collected 4 items\n", + "\n", + "test_nearest_square.py .... [100%]\n", + "\n", + "============================== 4 passed in 0.03s ==============================\n" + ] + } + ], "source": [ "! pytest test_nearest_square.py" ] @@ -386,11 +1259,27 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 72, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['normal', 'fairy']\n" + ] + } + ], "source": [ - "# Insert your code here" + "# Insert your code here\n", + "import requests\n", + "jigglypuff = requests.get('https://pokeapi.co/api/v2/pokemon/jigglypuff').json()\n", + "\n", + "type_list = list()\n", + "for type in jigglypuff['types']:\n", + " type_list.append(type['type']['name'])\n", + "\n", + "print(type_list)\n" ] }, { @@ -404,11 +1293,31 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 76, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['fighting', 'poison', 'steel']\n" + ] + } + ], "source": [ - "# Insert your code here" + "# Insert your code here\n", + "damage_type_0 = requests.get(jigglypuff['types'][0]['type']['url']).json()\n", + "damage_type_1 = requests.get(jigglypuff['types'][1]['type']['url']).json()\n", + "\n", + "damage_type_list = list()\n", + "for type in jigglypuff['types']:\n", + " damage_type = requests.get(type['type']['url']).json()\n", + " for double_damage_poke in damage_type['damage_relations']['double_damage_from']:\n", + " damage_type_list.append(double_damage_poke['name'])\n", + " for half_damage_poke in damage_type['damage_relations']['half_damage_from']:\n", + " damage_type_list.append(half_damage_poke['name'])\n", + "\n", + "print(double_damage_type_list)" ] }, { @@ -420,11 +1329,51 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "mankey\n", + "primeape\n", + "poliwrath\n", + "machop\n", + "machoke\n", + "\n", + "\n", + "bulbasaur\n", + "ivysaur\n", + "venusaur\n", + "weedle\n", + "kakuna\n", + "\n", + "\n", + "magnemite\n", + "magneton\n", + "forretress\n", + "steelix\n", + "scizor\n" + ] + } + ], "source": [ - "# Insert your code here" + "# Insert your code here\n", + "for i in range(1):\n", + " double_damage_type_0 = requests.get(damage_type_0['damage_relations']['double_damage_from'][i]['url']).json()\n", + " print('\\n')\n", + " for j in range(5):\n", + " print(double_damage_type_0['pokemon'][j]['pokemon']['name'])\n", + "\n", + "for i in range(2):\n", + " double_damage_type_1 = requests.get(damage_type_1['damage_relations']['double_damage_from'][i]['url']).json()\n", + " print('\\n')\n", + " for j in range(5):\n", + " print(double_damage_type_1['pokemon'][j]['pokemon']['name'])\n", + " \n" ] }, { @@ -438,21 +1387,21 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 70, "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", + "============================= test session starts =============================\n", + "platform win32 -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1\n", + "rootdir: C:\\Users\\91910\\Untitled Folder 1\n", + "collected 4 items\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", + "test_abilities.py .... [100%]\n", "\n", - "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 2.75s\u001b[0m\u001b[32m ===============================\u001b[0m\n" + "============================== 4 passed in 0.87s ==============================\n" ] } ], @@ -515,9 +1464,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.3" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..6ca0021 --- /dev/null +++ b/ability.py @@ -0,0 +1,10 @@ +import requests + +def ability(input_poke): + ability_list = list() + pokemon = requests.get('https://pokeapi.co/api/v2/pokemon/' + input_poke).json() + for ability in pokemon['abilities']: + ability_list.append(ability['ability']['name']) + return(ability_list) + + diff --git a/main.py b/main.py new file mode 100644 index 0000000..8e7ba49 --- /dev/null +++ b/main.py @@ -0,0 +1,11 @@ +import step_4 + +start = time.time()#stores the number of seconds passed since epoch +verified_elements = step_4.np_intersection(subset_elements, all_elements)#stores the intersection of subset_elements and all_elements +print(len(verified_elements))#prints length of intersection of subset_elements and all_elements +print('Duration: {} seconds'.format(time.time() - start))#prints time passed since start + +start = time.time()#stores the number of seconds passed since epoch +verified_elements = step_4.set_intersection(subset_elements, all_elements)#stores the intersection of subset_elements and all_elements +print(len(verified_elements))#prints length of intersection of subset_elements and all_elements +print('Duration: {} seconds'.format(time.time() - start))#prints time passed since start diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..979a05e --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,9 @@ +def nearest_square(num): + if num < 0: + return 0 + else: + for i in range(num, 0, -1): + print(i) + if i*i <= num: + return(i*i) + diff --git a/pokedex.py b/pokedex.py new file mode 100644 index 0000000..a2a1542 --- /dev/null +++ b/pokedex.py @@ -0,0 +1,58 @@ +import PySimpleGUI as sg +import requests + +def type(input_poke): + type_list = list() + pokemon = requests.get('https://pokeapi.co/api/v2/pokemon/' + input_poke).json() + for type in pokemon['types']: + type_list.append(type['type']['name']) + return(type_list) + +def double_damage_type(input_poke): + pokemon = requests.get('https://pokeapi.co/api/v2/pokemon/' + input_poke).json() + double_damage_type_list = list() + for type in pokemon['types']: + damage_type = requests.get(type['type']['url']).json() + for double_damage_poke in damage_type['damage_relations']['double_damage_from']: + double_damage_type_list.append(double_damage_poke['name']) + return(double_damage_type_list) + +def double_damage_poke(input_poke): + pokemon = requests.get('https://pokeapi.co/api/v2/pokemon/' + input_poke).json() + double_damage_poke_list = list() + for type in pokemon['types']: + damage_type = requests.get(type['type']['url']).json() + for double_damage_poke in damage_type['damage_relations']['double_damage_from']: + dd_poke = requests.get(double_damage_poke['url']).json() + for i in range(5): + double_damage_poke_list.append(dd_poke['pokemon'][i]['pokemon']['name']) + return(double_damage_poke_list) + +def ability(input_poke): + ability_list = list() + pokemon = requests.get('https://pokeapi.co/api/v2/pokemon/' + input_poke).json() + for ability in pokemon['abilities']: + ability_list.append(ability['ability']['name']) + return(ability_list) + +# Define the window's contents +layout = [[sg.Text("Enter name of pokemon: ")], + [sg.Input(key='-INPUT-')], + [sg.Text(size=(40,1), key='-OUTPUT-')], + [sg.Button('Ok'), sg.Button('Quit')]] + +# Create the window +window = sg.Window('Pokedex', layout) + +# Display and interact with the Window using an Event Loop +while True: + event, values = window.read() + # See if user wants to quit or window was closed + if event == sg.WINDOW_CLOSED or event == 'Quit': + break + # Output a message to the window + window['-OUTPUT-'].update('Hello there! Thanks for using Pokedex') + sg.popup('NAME: ', type(values['-INPUT-']), '\nDOUBLE DAMAGE FROM: ', double_damage_type(values['-INPUT-']), '\nDOUBLE DAMAGE FROM POKEMON LIST: ', double_damage_poke(values['-INPUT-']), '\nABILTIES: ', ability(values['-INPUT-'])) + +# Finish up by removing from the screen +window.close() diff --git a/step_4.py b/step_4.py new file mode 100644 index 0000000..0fbbeab --- /dev/null +++ b/step_4.py @@ -0,0 +1,50 @@ +import numpy as np +#imports numpy as np. NumPy contains a multi-dimensional array +#and matrix data structures. + +import time +#time provides many ways of representing time in code, +#such as objects, numbers, and strings. + +with open('subset_elemets.txt') as f: + subset_elements = f.read().split('\n')#stores all the elements in 'subset_elements.txt' + +with open('all_elements.txt') as f: + all_elements = f.read().split('\n')#stores all the elements in 'all_elements.txt' + +def np_intersection(x, y): + """Returns the intersection of the arrays passed as parameters using numpy module + + Parameters: + x (array): An array + y (array): An array + + Returns: + array: intersection of x and y + + """ + return np.intersect1d(x, y) + +def set_intersection(x, y): + """Returns the intersection of the lists passed as parameters using set operations + + Parameters: + x (list): A list + y (list): A list + + Returns: + set: intersection of x and y + + """ + return set(x).intersection(y) + +start = time.time()#stores the number of seconds passed since epoch +verified_elements = np_intersection(subset_elements, all_elements)#stores the intersection of subset_elements and all_elements +print(len(verified_elements))#prints length of intersection of subset_elements and all_elements +print('Duration: {} seconds'.format(time.time() - start))#prints time passed since start + +start = time.time()#stores the number of seconds passed since epoch +verified_elements = set_intersection(subset_elements, all_elements)#stores the intersection of subset_elements and all_elements +print(len(verified_elements))#prints length of intersection of subset_elements and all_elements +print('Duration: {} seconds'.format(time.time() - start))#prints time passed since start +