Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adithya kumar #4

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
85 changes: 74 additions & 11 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",
"It is code that runs on a production server, which means it is being used by the intended audience \n",
"#### Clean \n",
"(Insert answer here)\n",
"It is a readable, simple and concise code \n",
"#### Modular\n",
"(Insert answer here)\n",
"Code broken up into functions and modules which makes it more organized and reusable.\n",
"#### Module\n",
"(Insert answer here)\n",
"It allows the code to be reused in the same file or can be reused by other files by importing it.\n",
"#### Refactoring code\n",
"(Insert answer here)"
"It is the restructuring of code without changing its external behavior. "
]
},
{
Expand Down Expand Up @@ -171,7 +171,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Insert your solution here"
"# labels = list(df.columns)",
"labels = [word.replace(' ','_') for word in labels]",
"df.columns=labels"
]
},
{
Expand Down Expand Up @@ -261,7 +263,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Insert answer here\n",
"start = time.time()"
"verified_elements = []"
"verified_elements = np.intersect1d(subset_elements,all_elements)",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
Expand All @@ -280,7 +284,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Insert answer here\n",
"start = time.time()"
"verified_elements = set(subset_elements) & set(all_elements)\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
Expand Down Expand Up @@ -390,7 +395,14 @@
"metadata": {},
"outputs": [],
"source": [
"# Insert your code here"
"import pokebase as pb",
"import requests,json",
"def getType():",
" type_response = requests.get('https://pokeapi.co/api/v2/pokemon/psyduck')",
" text = json.loads(type_response.text)",
" for item in text['types']:",
" print(item['type']['name'])\n",
"getType()"
]
},
{
Expand All @@ -408,7 +420,25 @@
"metadata": {},
"outputs": [],
"source": [
"# Insert your code here"
"import pokebase as pb",
"import requests,json",
"def getType():",
" type_response = requests.get('https://pokeapi.co/api/v2/pokemon/psyduck')",
" text = json.loads(type_response.text)",
" type_url = []",
" for item in text['types']:",
" type_url.append(item['type']['url'])",
" return type_url\n",
"def get_weakness():",
" urls = getType()",
" for link in urls:",
" affect_res = requests.get(link)",
" affect_json = json.loads(affect_res.text)",
" print('Type :',affect_json['name'])",
" for values in affect_json['damage_relations']['double_damage_from']:",
" weakness = values['name']",
" print('weakness :',weakness)",
"get_weakness()"
]
},
{
Expand All @@ -424,7 +454,40 @@
"metadata": {},
"outputs": [],
"source": [
"# Insert your code here"
"import pokebase as pb",
"import requests,json",
"def getType():",
" type_response = requests.get('https://pokeapi.co/api/v2/pokemon/psyduck')",
" text = json.loads(type_response.text)",
" type_url = []",
" for item in text['types']:",
" type_url.append(item['type']['url'])",
" return type_url\n",
"def get_weakness():",
" urls = getType()",
" weak_types = []",
" for link in urls:",
" affect_res = requests.get(link)",
" affect_json = json.loads(affect_res.text)",
" print('Type :',affect_json['name'])",
" for values in affect_json['damage_relations']['double_damage_from']:",
" weakness = values['name']",
" weak_types.append(weakness)",
" return weak_types\n",
"def get_damage_pokemon():"
" types = get_weakness()"
" print('This pokemon is weak agianst pokemon: ')"
" for type in types:"
" count = 0"
" strong_response = requests.get('https://pokeapi.co/api/v2/type/{}/'.format(type))"
" strong_json = json.loads(strong_response.text)"
" print(type,':')"
" for data in strong_json['pokemon']:"
" print(data['pokemon']['name'])"
" count+=1"
" if count >= 5:"
" break"
"get_damage_pokemon()"
]
},
{
Expand Down
10 changes: 10 additions & 0 deletions ability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pokebase as pb
import requests,json

def ability(name):
res = requests.get("https://pokeapi.co/api/v2/pokemon/{}".format(name))
data = json.loads(res.text)
abilities = []
for values in data['abilities']:
abilities.append(values['ability']['name'])
return abilities
107 changes: 107 additions & 0 deletions get_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import pokebase as pb
import requests,json

def getType(name):
"""
Returns the type of the input pokemon

Parameters:
------------
name : str

Returns:
-----------
list of all types of the input pokemon
"""
type_response = requests.get('https://pokeapi.co/api/v2/pokemon/{}'.format(name))
text = json.loads(type_response.text)
type_name = []
for item in text['types']:
type_name.append(item['type']['name'])
return type_name

def getType_url(name):
"""
Returns the api url of the input pokemon types.

Parameters:
------------
name : str

Returns:
-----------
list of all url for types
"""
type_response = requests.get('https://pokeapi.co/api/v2/pokemon/{}'.format(name))
text = json.loads(type_response.text)
type_url = []
for item in text['types']:
type_url.append(item['type']['url'])
return type_url

def get_weakness(name):
"""
Returns the types that the input pokemon is weak against.

Parameters:
------------
name : str

Returns:
-----------
list of all the types the input pokemon is weak against
"""
urls = getType_url(name)
weak_types = []
for link in urls:
affect_res = requests.get(link)
affect_json = json.loads(affect_res.text)
for values in affect_json['damage_relations']['double_damage_from']:
weakness = values['name']
weak_types.append(weakness)
return weak_types

def get_damage_pokemon(name):
"""
Returns the name of the pokemons that the input pokemon is weak against

Parameters:
------------
name : str

Returns:
-----------
list of the names of pokemon the input pokemon is weak against
"""
types = get_weakness(name)
pokemons = []
for type in types:
count = 0
strong_response = requests.get('https://pokeapi.co/api/v2/type/{}/'.format(type))
strong_json = json.loads(strong_response.text)
for data in strong_json['pokemon']:
pokemons.append(data['pokemon']['name'])
count+=1
if count >= 5:
break
return pokemons

def ability(name):
"""
Returns the abilities of the input pokemon

Parameters:
------------
name : str

Returns:
-----------
list of all the abilities of input pokemon
"""
res = requests.get("https://pokeapi.co/api/v2/pokemon/{}".format(name))
data = json.loads(res.text)
abilities = []
for values in data['abilities']:
abilities.append(values['ability']['name'])
return abilities

9 changes: 9 additions & 0 deletions nearest_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import math

def nearest_square(number):
try:
nearest = math.floor(math.sqrt(number))
return nearest*nearest
except ValueError:
return 0

21 changes: 21 additions & 0 deletions pokedex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import PySimpleGUI as sg
import get_data as pk

layout = [[sg.Text("Enter pokemon: ")],
[sg.Input(key='-INPUT-')],
[sg.Text(size=(40,1), key='-OUTPUT-')],
[sg.Button('Ok'), sg.Button('Quit')]]
window = sg.Window('Pokedex',layout)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == 'Quit':
break
pokeName = values['-INPUT-']
sg.popup('Name:',pokeName,
'Type: ', pk.getType(pokeName),
'Weakness: ',pk.get_weakness(pokeName),
'Weak against: ',pk.get_damage_pokemon(pokeName),
'Abilities: ',pk.ability(pokeName)
)

window.close()
55 changes: 55 additions & 0 deletions step_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import time
import numpy as np

def usingNumpy(all_elem, subset):
"""
It gives the length of an array containing the common
values of two arrays using the numpy module

Parameters:
-----------
all_elem: array
subset: array

Returns:
-----------
Length of array containing the common elements of arrays passed in through the
arguments

"""
verified_elements = np.intersect1d(subset,all_elem)
return len(verified_elements)

def usingNormal(all_elem,subset):
"""
It gives the length of an array containing the common
values of two arrays using the inbuilt fuctions of python

Parameters:
-----------
all_elem: array
subset: array

Returns:
-----------
Length of array containing the common elements of arrays passed in through the
arguments

"""
verified_elements = set(all_elem) & set(subset)
return len(verified_elements)

if __name__ == "__main__":

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

start = time.time()
all_elements = np.array(all_elements)

print(usingNumpy(all_elements, subset_elements))
print(usingNormal(all_elements, subset_elements))
print('Duration: {} seconds'.format(time.time() - start))