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
858 changes: 816 additions & 42 deletions Python-ifed.ipynb

Large diffs are not rendered by default.

Binary file added __pycache__/ability.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/nearest_square.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/pokedex.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions ability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import requests

def ability(pokemon):
response = requests.get('https://pokeapi.co/api/v2/pokemon/'+pokemon)
abilities = response.json()['abilities']

ablility_list = []
for ind in range(len(abilities)):
ablility_list.append(abilities[ind]['ability']['name'])
return ablility_list

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

def nearest_square(num):
if num<0:
return 0
return(math.floor(math.sqrt(num))**2)


91 changes: 91 additions & 0 deletions pokedex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import requests
import json


def get_type(url):
'''
Gets the type of Pokemon

PARAMETERS:
-------------
url: string

RETURNS:
-------------
type of Pokemon : string

'''

response = requests.get(url)

name = response.json()['species']['name']
print(name)

poke_types = []
poke_type_list = response.json()['types']
for i in range(len(poke_type_list)):
poke_types.append(poke_type_list[i]['type']['name'])
print(poke_types)

return ", ".join(poke_types)


def damage_from(url):
'''
Gets the type of damage

PARAMETERS:
-------------
url: string

RETURNS:
-------------
type of damage : list

'''
response = requests.get(url)

list_to_return = []

types = response.json()['types']
for i in range(len(types)):
url = types[i]['type']['url']

response = requests.get(url)
dam_rel = response.json()['damage_relations']

# extracting every key with substring damage_from, except no_damage_from
damage_list = [value for key, value in dam_rel.items() if (
'damage_from' in key and 'no' not in key)]
# damage_from is a list of lists

for damage_from in damage_list:
# iterating through lists
for damage in damage_from:
#damage - dictionary
list_to_return.append(damage['name'])
print(damage['name'])
return list_to_return


def get5_attackers(url):
response = requests.get(url)

print("Double damage from:")
double_dam_url = []
dam_rel = response.json()['damage_relations']

for dam in range(len(dam_rel['double_damage_from'])):
double_dam_url.append(dam_rel['double_damage_from'][dam]['url'])
print(dam_rel['double_damage_from'][dam]['name'])
print((double_dam_url[0]))

attackers = []
for dam_url in double_dam_url:
response = requests.get(dam_url)
pokemon = response.json()['pokemon']
for ind in range(5):
attackers.append(pokemon[ind]['pokemon']['name'])
print(pokemon[ind]['pokemon']['name'])

return attackers
39 changes: 39 additions & 0 deletions pokedex_design.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import PySimpleGUI as sg
import pokedex as pd

# Define the window's contents
layout = [[sg.Text("Name of the pokemon")], # Part 2 - The Layout
[sg.Input()],
[sg.Button('Ok')],
]

# Create the window
window = sg.Window('Pokedex', layout)
# Display and interact with the Window
event, values = window.read()

pokemon = values[0].lower()
print('Pokemon: ', pokemon)

url = 'https://pokeapi.co/api/v2/pokemon/'+pokemon

poke_type = pd.get_type(url)
damage_from = pd.damage_from(url)
new_url = ['https://pokeapi.co/api/v2/pokemon/type/'+i for i in damage_from]
print(new_url)
poke_type_column = [
[sg.Text("Type: "+poke_type.capitalize())],
[sg.Text("Damage from: "+"".join(damage_from).capitalize())],
#[sg.Text("Attackers: "+"".join(pd.get5_attackers(new_url[0])).capitalize())],

[sg.Text(size=(40, 1), key="-TOUT-")],
]

menu = [[sg.Column(poke_type_column)]]
window = sg.Window('Pokedex', menu)
event, values = window.read()



# Finish up by removing from the screen
window.close()
101 changes: 101 additions & 0 deletions step_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import time
import numpy as np

def common_elems_num1(subset_elements, all_elements):
'''
Gets the number of common elements using the set operation - intersection
PARAMETERS:
-------------
subset_elements: list of strings,
all_elements : list of strings

RETURNS:
-------------
number of common elements and the duration for execution

'''

# records the starting time to calculate the time taken for implementation
start = time.time()

#converting the lists to set for implementing the intersection function
subset_elements = set(subset_elements)
all_elements = set(all_elements)

#intersection - returns all the common elements in both the list as a new set
verified_elements = subset_elements.intersection(all_elements)

# duration is calculated and printed
duration = time.time() - start

return (len(verified_elements), duration)

def common_elems_num2(subset_elements, all_elements):
'''
Gets the number of common elements using the NumPy array operation - intersect1d
PARAMETERS:
-------------
subset_elements: list of strings
all_elements : list of strings

RETURNS:
-------------
number of common elements and the duration for execution

'''
# records the starting time to calculate the time taken for implementation
start = time.time()

# an array of all the common elements is stored in verified_elements
verfied_elements = np.intersect1d(subset_elements,all_elements)

# recording the time taken
duration = time.time() - start

return len(verfied_elements), duration

def common_elems_num3(subset, all_elements):
'''
Gets the number of common elements using the traditional for-loop + comparison method
PARAMETERS:
-------------
subset_elements: list of strings
all_elements : list of strings

RETURNS:
-------------
number of common elements and the duration for execution

'''

#the time when the execution begins
start = time.time()
#an empty list to store the common elements from both the lists
verified_elements = []

for element in subset:
# looping through subset
if element in all_elements:
# checking if 'element' is present in 'all_elements' and appending to verified_elements
verified_elements.append(element)

#calculate duration
duration = time.time() - start
return len(verified_elements), duration


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')
#lines in the files are split and stored into the lists

print("Number of elements and time taken in s for three different approaches")
print("First approach: Using NumPy")
print(common_elems_num1(subset_elements, all_elements ))
print("\nSecond approach: Using Set")
print (common_elems_num2(subset_elements, all_elements ))
print("\nThird approach: Using traditional for loop and comparing")
print (common_elems_num3(subset_elements, all_elements ))
3 changes: 2 additions & 1 deletion test_nearest_square.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ def test_nearest_square_n12():
def test_nearest_square_9():
assert(nearest_square(9)==9)
def test_nearest_square_23():
assert(nearest_square(23)==16)
assert(nearest_square(23)==16)