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
358 changes: 321 additions & 37 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__/pokedexFunc.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,json

def ability(pokeName):
response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName)
response.raise_for_status()
pikachuData=response.json()
abilitiesData=pikachuData['abilities']
abilities=[]
for ability in abilitiesData:
abilities.append(ability['ability']['name'])
return abilities
7 changes: 7 additions & 0 deletions nearest_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def nearest_square(n):
if n>0:
for i in range(n):
if i*i <= n:
nearSq = i*i
return nearSq
return 0
34 changes: 34 additions & 0 deletions pokedex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import PySimpleGUI as sg
from pokedexFunc import pokeType,ability,TypeDoubleDmg,DoubleDmg5

sg.theme('DarkBlue')
layout = [[sg.Text("Enter Pokemon Name: ")],
[sg.Input(size=(35,1),key='-INPUT-')],
[sg.Text(size=(35,3), key='-Type-')],
[sg.Text(size=(35,2), key='-DDF-')],
[sg.Text(size=(35,7), key='-DDP-')],
[sg.Text(size=(35,8), key='-ABILITIES-')],
[sg.Button('Get Details'), sg.Button('Quit')]]

window = sg.Window('POKEDEX', layout, alpha_channel=0.95)

while True:
event, values = window.read()

if event == sg.WINDOW_CLOSED or event == 'Quit':
break

typeName=pokeType(values['-INPUT-'].lower())
double_damage_from=TypeDoubleDmg(typeName)
DoubleDamagePoksList=DoubleDmg5(double_damage_from)
doubleDamagePoks='\n--> '.join([str(i).upper() for i in DoubleDamagePoksList])
abilitiesList=ability(values['-INPUT-'].lower())
abilities='\n--> '.join([str(i).upper() for i in abilitiesList])

window['-Type-'].update('\nType: '+typeName.upper())
window['-DDF-'].update('Double Damage from type: '+double_damage_from.upper())
window['-DDP-'].update(f'Double Damage from pokemons:\n--> {doubleDamagePoks}')
window['-ABILITIES-'].update(f'Abilities:\n--> {abilities}')


window.close()
91 changes: 91 additions & 0 deletions pokedexFunc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#! python3
# pokedexFunc.py

import requests,json

def pokeType(pokeName):
'''Returns the type of pokemon passed in arguments

PARAMETERS:
-----------
pokeName : string
Name of the pokemon

RETURNS:
----------
typeName : string
Type of the pokemon
'''

response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName)
response.raise_for_status()
pikachuData=response.json()
typeData=pikachuData['types'][0]
typeName=typeData['type']['name']
return typeName

def TypeDoubleDmg(typeName):
'''Returns the pokemon type which gives 2x damage to the type passed in arguments

PARAMETERS:
-----------
typeName : string
Type of pokemon

RETURNS:
-----------
double_damage_from: string
Type of pokemon which gives 2x damage to pokeName
'''

response=requests.get("https://pokeapi.co/api/v2/type/"+typeName)
pikachuData=response.json()
damageData=pikachuData['damage_relations']
double_damage_from=damageData['double_damage_from'][0]['name']
return double_damage_from

def DoubleDmg5(double_damage_from):
'''Returns the list of five pokemons of the type passed in arguments

PARAMETERS:
-----------
double_damage_from : string
Type of pokemon

RETURNS:
------------
DDF : list
Names of five pokemon of type double_damage_from, in a list
'''

response=requests.get("https://pokeapi.co/api/v2/type/"+double_damage_from)
response.raise_for_status()
typeData=response.json()
pikachuData=typeData['pokemon']
DDF=[]
for i in range(5):
DDF.append(pikachuData[i]['pokemon']['name'])
return DDF

def ability(pokeName):
'''Returns the list of abilities of the pokemon passed in arguments

PARAMETERS:
-----------
pokeName : string
Name of pokemon

RETURNS:
------------
abilities : list
All abilities of pokeName, in a list
'''

response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName)
response.raise_for_status()
pikachuData=response.json()
abilitiesData=pikachuData['abilities']
abilities=[]
for ability in abilitiesData:
abilities.append(ability['ability']['name'])
return abilities
126 changes: 126 additions & 0 deletions step_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#! python3
# step_4.py
""" STEP-4
This script was made for learning how to optimize our python code.

It reads data from two .txt files, and prints the
number of lines which are same in both the .txt files.

This script requires that `pandas` be installed within the Python
environment you are running this script in.
"""

import time
import pandas as pd
import numpy as np

def openFiles():
"""Open two text files and stores each line in the of that file in a list
Parameters:
--------------
None

Returns:
-------------
subset_elements : list
a list of strings from subset_elemets.txt
all_elements : list
a list of strings from subset_elements.txt
"""

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')
return subset_elements,all_elements

def appendOldWay(subset_elements,all_elements):
"""Prints a list of elements and time taken to execute this function.

This function uses nested for loops and append() method to find the elements
which are present in both the lists passed as arguments, and stores them in a
new list. It prints the length of the new list along with time taken by this
function.

Parameters:
--------------
subset_elements : list
a list of strings
all_elements : list
a list of strings
Returns:
-------------
None
"""
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 appendNumPy(subset_elements, all_elements):
"""Prints a list of elements and time taken to execute this function.

This function uses NumPy methods to find the elements which are present
in both the lists passed as arguments, and stores them in a new list.
It prints the length of the new list along with time taken by this
function.

Parameters:
--------------
subset_elements : list
a list of strings
all_elements : list
a list of strings
Returns:
-------------
None
"""

start = time.time()
subsetArr=np.array(subset_elements)
allArr=np.array(all_elements)
verified_elements = np.array([])
verified_elements=np.intersect1d(subsetArr,allArr)
print(len(verified_elements))
print('Duration: {} seconds'.format(time.time() - start))

def appendDataStruct(subset_elements,all_elements):
"""Prints a list of elements and time taken to execute this function.

This function use of python data structures and set() method to find
the elements which are present in both the lists passed as arguments,
and stores them in a new list. It prints the length of the new list along
with time taken by this
function.

Parameters:
--------------
subset_elements : list
a list of strings
all_elements : list
a list of strings
Returns:
-------------
None
"""

start = time.time()
verified_elements = list(set(subset_elements)&set(all_elements))
print(len(verified_elements))
print(f'Duration: {time.time() - start} seconds')

def main():
subset_elements, all_elements=openFiles()
print('When Using old code with for loop--->')
appendOldWay(subset_elements,all_elements)
print("when using NumPy module's methods--->")
appendNumPy(subset_elements,all_elements)
print("When using python data structure's methods(sets)--->")
appendDataStruct(subset_elements,all_elements)

if __name__=="__main__":
main()