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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
refactorlist.py
numpyedit.py
datastredit.py
pokeapi.py
214 changes: 122 additions & 92 deletions Python-ifed.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@
"### Describe what each of the following means\n",
"\n",
"#### Production\n",
"(Insert answer here)\n",
"Production programming involves creating or modifying a software product to meet the needs of real customers. Production means anything that you need to work reliably, and consistently. When the code runs on a production system, that means it is being used by the intended audience in a real-world situation.\n",
"#### Clean \n",
"(Insert answer here)\n",
"Clean coding is 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.\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. These design approach is actually increase development time for programmers. Writing modular code means breaking down big functions into several smaller functions.\n",
"#### Module\n",
"(Insert answer here)\n",
"A module is a number of distinct but interrelated units from which a program may be built up or into which a complex activity may be analysed.\n",
"#### Refactoring code\n",
"(Insert answer here)"
"In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior. Refactoring is intended to improve the design, structure, and/or implementation of the software, while preserving its functionality."
]
},
{
Expand All @@ -92,17 +92,17 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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": "code",
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -112,10 +112,6 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"new_df = df.rename(columns={'team 1': 'team_1',\n",
" 'team 2': 'team_2',\n",
Expand All @@ -128,7 +124,11 @@
" 'umpire 2':'umpire_2'\n",
" })\n",
"new_df.head()"
]
],
"cell_type": "code",
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -138,10 +138,6 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"labels = list(df.columns)\n",
"labels[0] = labels[0].replace(' ', '_')\n",
Expand All @@ -156,7 +152,11 @@
"labels[10] = labels[10].replace(' ', '_')\n",
"df.columns = labels\n",
"df.head()"
]
],
"cell_type": "code",
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -166,13 +166,14 @@
]
},
{
"source": [
"df.columns=[x.replace(' ','_') for x in list(df.columns)]\n",
"df.head()"
],
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Insert your solution here"
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -208,7 +209,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -219,7 +220,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -232,10 +233,6 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"start = time.time()\n",
"verified_elements = []\n",
Expand All @@ -246,7 +243,11 @@
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
]
],
"cell_type": "code",
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -256,16 +257,15 @@
]
},
{
"source": [
"start = time.time()\n",
"verified_elements=np.nonzero(np.isin(np.array(subset_elements), np.array(all_elements)))\n",
"print(len(verified_elements[0]),'Duration: {} seconds'.format(time.time() - start),sep='\\n')"
],
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Insert answer here\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -275,20 +275,17 @@
]
},
{
"source": [
"start = time.time()\n",
"verified_elements=set(subset_elements) & set(all_elements)\n",
"print(len(verified_elements),'Duration: {} seconds'.format(time.time() - start),sep='\\n')"
],
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Insert answer here\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 4\n",
"# Documentation\n",
Expand All @@ -303,7 +300,9 @@
"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": {}
},
{
"cell_type": "markdown",
Expand All @@ -329,13 +328,13 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"! pytest test_nearest_square.py"
]
],
"cell_type": "code",
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -385,13 +384,24 @@
]
},
{
"source": [
"import requests as rq, sys\n",
"pokemon='golduck' #set pokemon here\n",
"def check(res): #check for errors\n",
" try:\n",
" res.raise_for_status()\n",
" except Exception as exc:\n",
" print('Error: '+exc)\n",
" sys.exit(1)\n",
"#code\n",
"res=rq.get('https://pokeapi.co/api/v2/pokemon/'+pokemon)\n",
"check(res)\n",
"print(res.json()['types'][0]['type']['name'])"
],
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Insert your code here"
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -403,13 +413,29 @@
]
},
{
"source": [
"import requests as rq, sys\n",
"pokemon='golduck' #set pokemon here\n",
"def check(res): #check for errors\n",
" try:\n",
" res.raise_for_status()\n",
" except Exception as exc:\n",
" print('Error: '+exc)\n",
" sys.exit(1)\n",
"#code\n",
"res=rq.get('https://pokeapi.co/api/v2/pokemon/'+pokemon)\n",
"check(res)\n",
"res=rq.get(res.json()['types'][0]['type']['url'])\n",
"lst=res.json()['damage_relations']\n",
"l=[]\n",
"for x in ['double_damage_from','half_damage_from']:\n",
" l+=[lst[x][y]['name'] for y in range(len(lst[x]))]\n",
"print(l)"
],
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Insert your code here"
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -419,13 +445,32 @@
]
},
{
"source": [
"import requests as rq, sys\n",
"pokemon='golduck' #set pokemon here\n",
"def check(res): #check for errors\n",
" try:\n",
" res.raise_for_status()\n",
" except Exception as exc:\n",
" print('Error: '+exc)\n",
" sys.exit(1)\n",
"#code\n",
"res=rq.get('https://pokeapi.co/api/v2/pokemon/'+pokemon)\n",
"check(res)\n",
"res=rq.get(res.json()['types'][0]['type']['url'])\n",
"lst=res.json()['damage_relations']\n",
"for x in ['double_damage_from']:\n",
" for y in range(len(lst[x])):\n",
" print('Type:'+lst[x][y]['name'])\n",
" r=rq.get('https://pokeapi.co/api/v2/type/'+lst[x][y]['name'])\n",
" check(r)\n",
" r=r.json()['pokemon']\n",
" print([r[z]['pokemon']['name'] for z in range(5)])"
],
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Insert your code here"
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -437,28 +482,13 @@
]
},
{
"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": "code",
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -515,7 +545,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.9.1-final"
}
},
"nbformat": 4,
Expand Down
Binary file added __pycache__/ability.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/nearest_square.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/pokemon.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading