Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 190 additions & 52 deletions Python-ifed.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 1\n",
"\n",
Expand All @@ -62,16 +60,18 @@
"### Describe what each of the following means\n",
"\n",
"#### Production\n",
"(Insert answer here)\n",
"Production programming involves creating or updating and testing software product to meet the needs of real customers.\n",
"#### Clean \n",
"(Insert answer here)\n",
"Clean code is readable and easy to understand by everyone whether the reader is the author of the code or a new programmer.\n",
"#### Modular\n",
"(Insert answer here)\n",
"Modular programming is the process of subdividing a computer program into separate sub-programs.\n",
"#### Module\n",
"(Insert answer here)\n",
"A module is a separate software component. It can often be used in a variety of applications. It reduces its complexity to some degree and it creates a number of well-defined, documented boundries within the program.\n",
"#### Refactoring code\n",
"(Insert answer here)"
]
"Refactoring is a systematic process of improving code without creating new functionality that can transform a mess into clean code and simple design."
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -167,11 +167,63 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 39,
"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": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Season</th>\n <th>city</th>\n <th>date</th>\n <th>team_1</th>\n <th>team_2</th>\n <th>toss_winner</th>\n <th>toss_decision</th>\n <th>result</th>\n <th>dl_applied</th>\n <th>winner</th>\n <th>win_by_runs</th>\n <th>win_by_wickets</th>\n <th>player_of_match</th>\n <th>venue</th>\n <th>umpire_1</th>\n <th>umpire_2</th>\n </tr>\n <tr>\n <th>id</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>1</th>\n <td>IPL-2017</td>\n <td>Hyderabad</td>\n <td>05-04-2017</td>\n <td>Sunrisers Hyderabad</td>\n <td>Royal Challengers Bangalore</td>\n <td>Royal Challengers Bangalore</td>\n <td>field</td>\n <td>normal</td>\n <td>0</td>\n <td>Sunrisers Hyderabad</td>\n <td>35</td>\n <td>0</td>\n <td>Yuvraj Singh</td>\n <td>Rajiv Gandhi International Stadium, Uppal</td>\n <td>AY Dandekar</td>\n <td>NJ Llong</td>\n </tr>\n <tr>\n <th>2</th>\n <td>IPL-2017</td>\n <td>Pune</td>\n <td>06-04-2017</td>\n <td>Mumbai Indians</td>\n <td>Rising Pune Supergiant</td>\n <td>Rising Pune Supergiant</td>\n <td>field</td>\n <td>normal</td>\n <td>0</td>\n <td>Rising Pune Supergiant</td>\n <td>0</td>\n <td>7</td>\n <td>SPD Smith</td>\n <td>Maharashtra Cricket Association Stadium</td>\n <td>A Nand Kishore</td>\n <td>S Ravi</td>\n </tr>\n <tr>\n <th>3</th>\n <td>IPL-2017</td>\n <td>Rajkot</td>\n <td>07-04-2017</td>\n <td>Gujarat Lions</td>\n <td>Kolkata Knight Riders</td>\n <td>Kolkata Knight Riders</td>\n <td>field</td>\n <td>normal</td>\n <td>0</td>\n <td>Kolkata Knight Riders</td>\n <td>0</td>\n <td>10</td>\n <td>CA Lynn</td>\n <td>Saurashtra Cricket Association Stadium</td>\n <td>Nitin Menon</td>\n <td>CK Nandan</td>\n </tr>\n <tr>\n <th>4</th>\n <td>IPL-2017</td>\n <td>Indore</td>\n <td>08-04-2017</td>\n <td>Rising Pune Supergiant</td>\n <td>Kings XI Punjab</td>\n <td>Kings XI Punjab</td>\n <td>field</td>\n <td>normal</td>\n <td>0</td>\n <td>Kings XI Punjab</td>\n <td>0</td>\n <td>6</td>\n <td>GJ Maxwell</td>\n <td>Holkar Cricket Stadium</td>\n <td>AK Chaudhary</td>\n <td>C Shamshuddin</td>\n </tr>\n <tr>\n <th>5</th>\n <td>IPL-2017</td>\n <td>Bangalore</td>\n <td>08-04-2017</td>\n <td>Royal Challengers Bangalore</td>\n <td>Delhi Daredevils</td>\n <td>Royal Challengers Bangalore</td>\n <td>bat</td>\n <td>normal</td>\n <td>0</td>\n <td>Royal Challengers Bangalore</td>\n <td>15</td>\n <td>0</td>\n <td>KM Jadhav</td>\n <td>M Chinnaswamy Stadium</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 39
}
],
"source": [
"# Insert your solution here"
"labels = list(df.columns)\n",
"df.columns = [list(df.columns)[i].replace(' ', '_') for i in range(len(labels))] \n",
"df.head()"
]
},
{
Expand Down Expand Up @@ -227,15 +279,22 @@
" subset_elements = f.read().split('\\n')\n",
" \n",
"with open('all_elements.txt') as f:\n",
" all_elements = f.read().split('\\n')\n",
" "
" all_elements = f.read().split('\\n') "
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 40,
"metadata": {},
"outputs": [],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"96\nDuration: 14.42495083808899 seconds\n"
]
}
],
"source": [
"start = time.time()\n",
"verified_elements = []\n",
Expand All @@ -257,11 +316,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 41,
"metadata": {},
"outputs": [],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"96\nDuration: 0.03100132942199707 seconds\n"
]
}
],
"source": [
"# Insert answer here\n",
"start = time.time()\n",
"a = np.array(subset_elements)\n",
"b = np.array(all_elements)\n",
"verified_elements = a[np.in1d(a, b)]\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
Expand All @@ -276,11 +346,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 42,
"metadata": {},
"outputs": [],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"96\nDuration: 0.006000041961669922 seconds\n"
]
}
],
"source": [
"# Insert answer here\n",
"start = time.time()\n",
"a = set(subset_elements)\n",
"b = set(all_elements)\n",
"verified_elements = a.intersection(b)\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
Expand Down Expand Up @@ -386,11 +467,26 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 43,
"metadata": {},
"outputs": [],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"water\n"
]
}
],
"source": [
"# Insert your code here"
"import requests\n",
"import json\n",
"\n",
"name = 'psyduck'\n",
"url = 'https://pokeapi.co/api/v2/pokemon/%s'%(name)\n",
"response = requests.get(url)\n",
"type_data =json.loads(response.text)\n",
"print(type_data['types'][0]['type']['name'])"
]
},
{
Expand All @@ -404,11 +500,30 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 44,
"metadata": {},
"outputs": [],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"grass\nelectric\nsteel\nfire\nwater\nice\n"
]
}
],
"source": [
"# Insert your code here"
"import requests\n",
"import json\n",
"\n",
"url = 'https://pokeapi.co/api/v2/type/11/'\n",
"response = requests.get(url)\n",
"type_data =json.loads(response.text)\n",
"a = len(type_data['damage_relations']['double_damage_from'])\n",
"b = len(type_data['damage_relations']['half_damage_from'])\n",
"for i in range(a):\n",
" print(type_data['damage_relations']['double_damage_from'][i]['name'])\n",
"for i in range(b):\n",
" print(type_data['damage_relations']['half_damage_from'][i]['name'])"
]
},
{
Expand All @@ -420,11 +535,45 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"execution_count": 45,
"metadata": {
"tags": []
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"bulbasaur It's type is grass\n",
"ivysaur It's type is grass\n",
"venusaur It's type is grass\n",
"oddish It's type is grass\n",
"gloom It's type is grass\n",
"pikachu It's type is electric\n",
"raichu It's type is electric\n",
"magnemite It's type is electric\n",
"magneton It's type is electric\n",
"voltorb It's type is electric\n"
]
}
],
"source": [
"# Insert your code here"
"import requests\n",
"import json\n",
"\n",
"url = 'https://pokeapi.co/api/v2/type/11/'\n",
"response = requests.get(url)\n",
"type_data =json.loads(response.text)\n",
"a = len(type_data['damage_relations']['double_damage_from'])\n",
"b = []\n",
"for i in range(a):\n",
" b.append(type_data['damage_relations']['double_damage_from'][i]['name'])\n",
"for j in b:\n",
" url2 = 'https://pokeapi.co/api/v2/type/%s'%(j)\n",
" response2 = requests.get(url2)\n",
" type_data2 =json.loads(response2.text)\n",
" for k in range(5):\n",
" print(type_data2['pokemon'][k]['pokemon']['name'], \"It's type is\", j)"
]
},
{
Expand All @@ -438,24 +587,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"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"
]
}
],
"outputs": [],
"source": [
"!pytest test_abilities.py"
]
Expand Down Expand Up @@ -501,9 +635,13 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
"name": "python3",
"display_name": "Python 3.7.1 32-bit",
"metadata": {
"interpreter": {
"hash": "8e61c9422603e3d3820d3aeca1b8eefe471d1a1023a28a3903412dc32402bf43"
}
}
},
"language_info": {
"codemirror_mode": {
Expand All @@ -515,7 +653,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.7.1-final"
}
},
"nbformat": 4,
Expand Down
14 changes: 14 additions & 0 deletions ability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests
import json

def ability(name_str):
name = name_str
url = 'https://pokeapi.co/api/v2/pokemon/%s'%(name)
response = requests.get(url)
type_data =json.loads(response.text)
a = len(type_data['abilities'])
lst_ability = []
for i in range(a):
lst_ability.append(type_data['abilities'][i]['ability']['name'])
return lst_ability

26 changes: 26 additions & 0 deletions nearest_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import math
# Importing math for mathematical functions

def nearest_square(n):
'''nearest_square

Parameters:
n (int): To get the nearest square below n

Returns:
int 0 : if n is less than 0
int i : nearest square number but less than n

'''
if n<0:
return 0
else:

# To find the square of the given number n
root = math.sqrt(n)
for i in range(n,-1,-1):
if int(root)**2 ==i:
return i
else:
continue

Loading