From 1e0a99b5996a5ed93130b921cf76176a4b9c4901 Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 00:30:54 +0530 Subject: [PATCH 1/9] step 1 completed --- Python-ifed.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..7bef8ef 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -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", "#### Module\n", - "(Insert answer here)\n", + "Code broken up into functions and modules which makes it more organized and reusable.\n", "#### Refactoring code\n", - "(Insert answer here)" + "It is the restructuring of code without changing its external behavior." ] }, { From 952886b4a91ab0651bc362f37110a8cad7949266 Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 00:37:31 +0530 Subject: [PATCH 2/9] step 2 completed --- Python-ifed.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 7bef8ef..7d13684 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -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" ] }, { From be5d8ef0620506a8223afa2d3f570f82f27ccd00 Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 00:46:27 +0530 Subject: [PATCH 3/9] step 3 completed --- Python-ifed.ipynb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 7d13684..9563465 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -263,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))" @@ -282,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))" From 3b69b6cce0d992463627d6c432152ee60354af53 Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 00:48:54 +0530 Subject: [PATCH 4/9] step 4 completed --- step_4.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 step_4.py diff --git a/step_4.py b/step_4.py new file mode 100644 index 0000000..84ed7a6 --- /dev/null +++ b/step_4.py @@ -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)) \ No newline at end of file From 091c1dadfbec2f0e988defbeadb42e095bae6ba5 Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 00:49:57 +0530 Subject: [PATCH 5/9] step 5 completed --- nearest_square.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 nearest_square.py diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..e3ca72e --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,9 @@ +import math + +def nearest_square(number): + try: + nearest = math.floor(math.sqrt(number)) + return nearest*nearest + except ValueError: + return 0 + From fa53c741566d5655a8809a24e3825ba2f5132983 Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 00:56:20 +0530 Subject: [PATCH 6/9] fixed file not loading issue --- Python-ifed.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 9563465..0fd6cbc 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -171,8 +171,8 @@ "metadata": {}, "outputs": [], "source": [ - "# labels = list(df.columns)" - "labels = [word.replace(' ','_') for word in labels]" + "# labels = list(df.columns)", + "labels = [word.replace(' ','_') for word in labels]", "df.columns=labels" ] }, From 97912797813f97c55d788a7b61da9e5550f198bc Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 13:15:14 +0530 Subject: [PATCH 7/9] step 1 corrected --- Python-ifed.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 0fd6cbc..f68802a 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -62,15 +62,15 @@ "### Describe what each of the following means\n", "\n", "#### Production\n", - "It is code that runs on a production server, which means it is being used by the intended audience\n", + "It is code that runs on a production server, which means it is being used by the intended audience \n", "#### Clean \n", - "It is a readable, simple and concise code\n", + "It is a readable, simple and concise code \n", "#### Modular\n", - "(Insert answer here)\n", - "#### Module\n", "Code broken up into functions and modules which makes it more organized and reusable.\n", + "#### Module\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", - "It is the restructuring of code without changing its external behavior." + "It is the restructuring of code without changing its external behavior. " ] }, { From bb85a72d50eecf0b7a589c6d0e490c88304e14e4 Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 15:41:29 +0530 Subject: [PATCH 8/9] completed challenge 2 --- Python-ifed.ipynb | 64 ++++++++++++++++++++++++++++++++++++++++++++--- ability.py | 10 ++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 ability.py diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index f68802a..0a2d40b 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -395,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()" ] }, { @@ -413,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()" ] }, { @@ -429,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()" ] }, { diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..f2191c6 --- /dev/null +++ b/ability.py @@ -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 From dab78a8dd65025550afa049cbe5595af87748378 Mon Sep 17 00:00:00 2001 From: R Adithya Kumar Date: Sun, 10 Jan 2021 18:27:49 +0530 Subject: [PATCH 9/9] Extra challenge complete --- get_data.py | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ pokedex.py | 21 +++++++++++ 2 files changed, 128 insertions(+) create mode 100644 get_data.py create mode 100644 pokedex.py diff --git a/get_data.py b/get_data.py new file mode 100644 index 0000000..0b2dea0 --- /dev/null +++ b/get_data.py @@ -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 + diff --git a/pokedex.py b/pokedex.py new file mode 100644 index 0000000..1ab2740 --- /dev/null +++ b/pokedex.py @@ -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()