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
136 changes: 93 additions & 43 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 means where we can work relaibly and consistently.Production code is the code that is used by clients.But it should not be necessarily stable and relaible.\n",
"#### Clean \n",
"(Insert answer here)\n",
"The code that is readable and anyone who reads the code must easly understand it even if its read by someone new to that.It should also be easy to understand and change whenever required.\n",
"#### Modular\n",
"(Insert answer here)\n",
"It is the code in which a complex problem is divided to sub sub problems until each of them can be solved independantly and easly.\n",
"#### Module\n",
"(Insert answer here)\n",
"Module is a piece of code created and maintained independantly and can be used in different systems.\n",
"#### Refactoring code\n",
"(Insert answer here)"
"The process of redesigining the code without any change in its logic,external behavior and functionality."
]
},
{
Expand Down Expand Up @@ -171,7 +171,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Insert your solution here"
"# Insert your solution here\n",
"df.columns = df.columns.str.replace(' ','_')\n",
"df.head()"
]
},
{
Expand Down Expand Up @@ -262,6 +264,11 @@
"outputs": [],
"source": [
"# Insert answer here\n",
"start=time.time()\n",
"\n",
"verified_elements=np.intersect1d(all_elements,subset_elements)\n",
"#using numpy inbuilt function because as per definition:\n",
"#In vectorisation we can replace for loop with numpy function\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
Expand All @@ -281,6 +288,10 @@
"outputs": [],
"source": [
"# Insert answer here\n",
"start=time.time()\n",
"\n",
"#using datastructure set.\n",
"verified_elements=list(set(all_elements)&set(subset_elements))\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
Expand Down Expand Up @@ -378,19 +389,28 @@
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Remember you were in a pokemon room (discord) what is the **type** of that pokemon"
]
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Insert your code here"
"# Insert your code here\n",
"import requests\n",
"\n",
"urll = \"http://pokeapi.co/api/v2/pokemon/gyarados/\"\n",
"urls=[]\n",
"data = requests.get(urll).json()\n",
"for i in range (2):\n",
" poke_type=data[\"types\"][i]['type']['name']\n",
" urls.append(data[\"types\"][i]['type']['url']) #appending url for step 2\n",
" print(poke_type)\n"
]
},
{
Expand All @@ -403,13 +423,24 @@
]
},
{
"source": [
"# Insert your code here\n",
"d_dmg_url=[]\n",
"tp=[]\n",
"for url in urls:\n",
" poke_type=requests.get(url).json()\n",
" for j in poke_type[\"damage_relations\"][\"double_damage_from\"]:\n",
" print(j[\"name\"])\n",
" tp.append(j[\"name\"])\n",
" d_dmg_url.append(j[\"url\"])\n",
" for j in poke_type[\"damage_relations\"][\"half_damage_from\"]:\n",
" print(j[\"name\"])\n",
"\n"
],
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Insert your code here"
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -420,11 +451,39 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 27,
"metadata": {},
"outputs": [],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Pokemon of Type: ghost\n",
"gastly,haunter,gengar,misdreavus,shedinja\n",
"\n",
"Pokemon of Type: dark\n",
"umbreon,murkrow,sneasel,houndour,houndoom\n",
"\n",
"Pokemon of Type: ground\n",
"sandshrew,sandslash,nidoqueen,nidoking,diglett\n",
"\n",
"Pokemon of Type: psychic\n",
"abra,kadabra,alakazam,slowpoke,slowbro\n",
"\n"
]
}
],
"source": [
"# Insert your code here"
"# Insert your code here\n",
"for i in range(len(d_dmg_url)):\n",
" dat=requests.get(d_dmg_url[i]).json()\n",
" print(\"Pokemon of Type: \"+tp[i])\n",
" for j in range(5):\n",
" print(dat[\"pokemon\"][j][\"pokemon\"][\"name\"],end='')\n",
" if j!=4:\n",
" print(end=',')\n",
" \n",
" print(\"\\n\")"
]
},
{
Expand All @@ -438,34 +497,21 @@
},
{
"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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Please version till this point saying with a message \"Completed challenge 2\""
]
],
"cell_type": "code",
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -501,9 +547,13 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
"name": "python3",
"display_name": "Python 3.8.0 64-bit",
"metadata": {
"interpreter": {
"hash": "06e483f59aeb05a49d223db5b746e2d43658eec77bca882da011caef50b704e4"
}
}
},
"language_info": {
"codemirror_mode": {
Expand All @@ -515,7 +565,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.0-final"
}
},
"nbformat": 4,
Expand Down
Binary file added __pycache__/ability.cpython-38.pyc
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions ability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import requests
def ability(name):
url = "http://pokeapi.co/api/v2/pokemon/"+name+"/"
data = requests.get(url).json()
ably=[]
for i in data["abilities"]:
ably.append(i['ability']['name'])
return ably

1 change: 1 addition & 0 deletions data.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data1.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions nearest_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import math
def nearest_square(num):
if num<0:
return 0
num=int(math.sqrt(num))
return num**2
88 changes: 88 additions & 0 deletions pokedex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import PySimpleGUI as sg
import requests


layout = [[sg.Text("Enter the name of Pokemon:")],
[sg.Input(key='-INPUT-')],
[sg.Text(size=(100,1), key='-OUTPUT1-')],
[sg.Text(size=(100,1), key='-OUTPUT2-')],
[sg.Text(size=(100,3), key='-OUTPUT3-')],
[sg.Text(size=(100,15), key='-OUTPUT4-')],
[sg.Text(size=(100,1), key='-OUTPUT5-')],
[sg.Button('Search'), sg.Button('Quit')]]

def ability(name):
url = "http://pokeapi.co/api/v2/pokemon/"+name+"/"
data = requests.get(url).json()
ably=[]
for i in data["abilities"]:
ably.append(i['ability']['name'])
return ably



window = sg.Window('PokeDex', layout)

while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == 'Quit':
break

Details="Name of the pokemon:"+values['-INPUT-']
window['-OUTPUT1-'].update(Details)
name=values["-INPUT-"]
#####################################TYPE############################################################
urll = "http://pokeapi.co/api/v2/pokemon/"+name+"/"
urls=[]
tp=[]
data = requests.get(urll).json()
for i in range (2):
poke_type=data["types"][i]['type']['name']
urls.append(data["types"][i]['type']['url']) #appending url for step 2
tp.append(poke_type)

Details="Type of pokemon is: "+str(tp)
window['-OUTPUT2-'].update(Details)

################################DOUBLE DAMAGE#########################################################


Details="Double Damage are given by the following type: \n"
d_dmg_url=[]
cn=0
tpp=tp
tp=[]
for url in urls:
poke_type=requests.get(url).json()
Details+="Double Damage for "+tpp[cn]+" by: "
cn+=1
for j in poke_type["damage_relations"]["double_damage_from"]:
Details+=j["name"]+' '
tp.append(j["name"])
d_dmg_url.append(j["url"])
Details+='\n'
window['-OUTPUT3-'].update(Details)

######################################List 5 pokemon###################################################
Details='List 5 pokemons which gives the given pokemon double damage:\n'
print(d_dmg_url)
for i in range(len(d_dmg_url)):
dat=requests.get(d_dmg_url[i]).json()
Details+=("Pokemon of Type: "+tp[i]+'\n')
for j in range(5):
Details+=(dat["pokemon"][j]["pokemon"]["name"])
if j!=4:
Details+=(',')
Details+=("\n\n")

window['-OUTPUT4-'].update(Details)
##################################ABILITY###############################################################
Details="Ability: "+str(ability(values['-INPUT-']))
window['-OUTPUT5-'].update(Details)

window.close()

# What is the type of pokemon
# What type of pokemon gives double damages to the given pokemon
# List 5 pokemons which gives the given pokemon double damage
# Abilities of our pokemon
54 changes: 54 additions & 0 deletions step_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import time
import numpy as np

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')

def withloop():
"""Name: function1
Description: This is a function which finds the the common elements in two lists using a for loop"""
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 withnumpy():
"""Name: function2
Description: This is a function which finds the the common elements in
two lists using an inbuilt function called intersect1d in numpy"""
start = time.time()
verified_elements=np.intersect1d(all_elements,subset_elements)

print(len(verified_elements))
print('Duration: {} seconds'.format(time.time() - start))

def withDS():
"""Name: function3
Description: This is a function which finds the the common elements in two lists using set.
"""
start=time.time()

#using datastructure set.
verified_elements=list(set(all_elements)&set(subset_elements))

print(len(verified_elements))
print('Duration: {} seconds'.format(time.time() - start))

def main():
print(withloop.__doc__)
withloop()
print(withnumpy.__doc__)
withnumpy()
print(withDS.__doc__)
withDS()

if __name__ == "__main__":
main()
Loading