From bb208330e7aa2322c7c848c3424a75175f89b157 Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 00:17:47 +0530 Subject: [PATCH 01/10] step 1 completed --- Python-ifed.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..326d6e0 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", + "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." ] }, { From cf2608d7ccd15d49ddae8b6b9a2e83845cd8c1a7 Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 00:46:26 +0530 Subject: [PATCH 02/10] 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 326d6e0..b959eb0 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -171,7 +171,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Insert your solution here" + "# Insert your solution here\n", + "new_df=df;new_df.columns = df.columns.str.replace(' ','_')\n", + "new_df.head()" ] }, { From f381e8905af8c26e819b7bcc81794f40aab01f8d Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 00:47:40 +0530 Subject: [PATCH 03/10] step 3 completed --- Python-ifed.ipynb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index b959eb0..c26afd6 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -264,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))" @@ -283,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))" From b03c4f97f845e1ad15f32524069fd5d60f6b6583 Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 00:48:22 +0530 Subject: [PATCH 04/10] step 4 completed --- step_4.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 step_4.py diff --git a/step_4.py b/step_4.py new file mode 100644 index 0000000..67edd2c --- /dev/null +++ b/step_4.py @@ -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() \ No newline at end of file From c826945cc66005377d6d42696ffc69af0d41e42f Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 00:49:13 +0530 Subject: [PATCH 05/10] step 5 completed --- nearest_square.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 nearest_square.py diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..2bc0beb --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,6 @@ +import math +def nearest_square(num): + if num<0: + return 0 + num=int(math.sqrt(num)) + return num**2 \ No newline at end of file From 0cf14ba90482a9e5a8c3e1512de1494ef158b0be Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 10:53:56 +0530 Subject: [PATCH 06/10] challenge 2 step 1 completed --- Python-ifed.ipynb | 27 ++++++++++++++++----------- tempCodeRunnerFile.py | 1 + test.py | 8 ++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 tempCodeRunnerFile.py create mode 100644 test.py diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index c26afd6..834ac8f 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -172,8 +172,8 @@ "outputs": [], "source": [ "# Insert your solution here\n", - "new_df=df;new_df.columns = df.columns.str.replace(' ','_')\n", - "new_df.head()" + "df.columns = df.columns.str.replace(' ','_')\n", + "df.head()" ] }, { @@ -389,19 +389,20 @@ ] }, { - "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": 3, "metadata": {}, "outputs": [], "source": [ - "# Insert your code here" + "# Insert your code here\n", + "import pokebase as pb\n" ] }, { @@ -512,9 +513,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": { @@ -526,7 +531,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.0-final" } }, "nbformat": 4, diff --git a/tempCodeRunnerFile.py b/tempCodeRunnerFile.py new file mode 100644 index 0000000..4ffa2bd --- /dev/null +++ b/tempCodeRunnerFile.py @@ -0,0 +1 @@ +data = response.json() \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..19ea97d --- /dev/null +++ b/test.py @@ -0,0 +1,8 @@ +import requests + +url = "http://pokeapi.co/api/v2/pokemon/gyarados/" + +data = requests.get(url).json() +for i in range (2): + poke_type=data["types"][i]['type']['name'] + print(poke_type) From c6c724b0424c23b59e24e5e8cff039c52b0d86cc Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 12:59:31 +0530 Subject: [PATCH 07/10] Completed challenge 2 --- Python-ifed.ipynb | 119 ++++++++++++++---- __pycache__/ability.cpython-38.pyc | Bin 0 -> 441 bytes ...test_abilities.cpython-38-pytest-6.2.1.pyc | Bin 0 -> 1990 bytes ability.py | 9 ++ data.json | 1 + data1.json | 1 + test.py | 24 +++- 7 files changed, 126 insertions(+), 28 deletions(-) create mode 100644 __pycache__/ability.cpython-38.pyc create mode 100644 __pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc create mode 100644 ability.py create mode 100644 data.json create mode 100644 data1.json diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 834ac8f..214b7d6 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -397,12 +397,28 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "water\nflying\n" + ] + } + ], "source": [ "# Insert your code here\n", - "import pokebase as pb\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" ] }, { @@ -415,12 +431,43 @@ ] }, { + "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", + " \n" + ], "cell_type": "code", - "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [ - "# Insert your code here" + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "grass\n", + "electric\n", + "steel\n", + "fire\n", + "water\n", + "ice\n", + "rock\n", + "electric\n", + "ice\n", + "fighting\n", + "bug\n", + "grass\n" + ] + } ] }, { @@ -432,11 +479,42 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Pokemon of Type: grass\n", + "bulbasaur,ivysaur,venusaur,oddish,gloom\n", + "\n", + "Pokemon of Type: electric\n", + "pikachu,raichu,magnemite,magneton,voltorb\n", + "\n", + "Pokemon of Type: rock\n", + "geodude,graveler,golem,onix,rhyhorn\n", + "\n", + "Pokemon of Type: electric\n", + "pikachu,raichu,magnemite,magneton,voltorb\n", + "\n", + "Pokemon of Type: ice\n", + "dewgong,cloyster,jynx,lapras,articuno\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\")" ] }, { @@ -450,21 +528,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 17, "metadata": {}, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "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" + "============================= test session starts =============================\nplatform win32 -- Python 3.8.0, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\nrootdir: c:\\Users\\geo\\Desktop\\Python-ifed-challenge\ncollected 4 items\n\ntest_abilities.py FFFF [100%]\n\n================================== FAILURES ===================================\n____________________________ test_ability_machamp _____________________________\n\n def test_ability_machamp():\n> assert(ability(\"machamp\")==['guts', 'no-guard', 'steadfast'])\nE AssertionError: assert None == ['guts', 'no-guard', 'steadfast']\nE + where None = ability('machamp')\n\ntest_abilities.py:4: AssertionError\n---------------------------- Captured stdout call -----------------------------\n['guts', 'no-guard', 'steadfast']\n____________________________ test_ability_pikachu _____________________________\n\n def test_ability_pikachu():\n> assert(ability(\"pikachu\")==['static', 'lightning-rod'])\nE AssertionError: assert None == ['static', 'lightning-rod']\nE + where None = ability('pikachu')\n\ntest_abilities.py:7: AssertionError\n---------------------------- Captured stdout call -----------------------------\n['static', 'lightning-rod']\n___________________________ test_ability_charizard ____________________________\n\n def test_ability_charizard():\n> assert(ability(\"charizard\")==['blaze', 'solar-power'])\nE AssertionError: assert None == ['blaze', 'solar-power']\nE + where None = ability('charizard')\n\ntest_abilities.py:10: AssertionError\n---------------------------- Captured stdout call -----------------------------\n['blaze', 'solar-power']\n______________________________ test_ability_evee ______________________________\n\n def test_ability_evee():\n> assert(ability(\"eevee\")==['run-away', 'adaptability', 'anticipation'])\nE AssertionError: assert None == ['run-away', 'adaptability', 'anticipation']\nE + where None = ability('eevee')\n\ntest_abilities.py:13: AssertionError\n---------------------------- Captured stdout call -----------------------------\n['run-away', 'adaptability', 'anticipation']\n=========================== short test summary info ===========================\nFAILED test_abilities.py::test_ability_machamp - AssertionError: assert None ...\nFAILED test_abilities.py::test_ability_pikachu - AssertionError: assert None ...\nFAILED test_abilities.py::test_ability_charizard - AssertionError: assert Non...\nFAILED test_abilities.py::test_ability_evee - AssertionError: assert None == ...\n============================== 4 failed in 6.45s ==============================\n" ] } ], @@ -473,11 +544,13 @@ ] }, { - "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", diff --git a/__pycache__/ability.cpython-38.pyc b/__pycache__/ability.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0aa318ef7371933a31a931654453b197b2bec5f3 GIT binary patch literal 441 zcmYjNF-yZx5WY)ZYn9eXEFE2h3~fMgDI%hsiy&P>MAN)y8k;6*-m4HvHh)Mv3jU(E zI=MM_@)A4rgZsX__i=ZRn{+xyKzRPzKK+t@SH(UIDsCv`2@wa55jemNZhnA+93Q}9 zKjgsJ$4Yi+kXCU=A#aH|7SN@>E|jQXjRkISZET=40w~Rb=Jj9%kEbOo%(YoC&U(Nb zJ=h?^^1Lu|bUgwpI)Cb4dMX)0oFH8MtD)#fUTG~=G~9Og}Mn-&swPP7s bb*nnB*X&V;4Bfg~BzzT#>*~a^8q~r+1#D-) literal 0 HcmV?d00001 diff --git a/__pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc b/__pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..90400cba1607ab98e22ff6503103e51f9fa57365 GIT binary patch literal 1990 zcmds2OK%fN5bmCr$Bq+;R|vOUkeGv`@LCp>pdjFaR%j(2hmoaG$K9Tc((_Pvd$Tt7 zg>VOPMhHs?$$x3Coc1r|v{f@EvJoJ`ZFj7$XS=JX>Z_V(tE(*nPx<;JdQS=YjLPC; zfwBinKLWxDr;>!U;#O)~gp$+=U5Xw{dZ`zBAluw|MZyMmxd+_m4ekSP@+NNqZ*lsB z1S|i*dE{|G%Ldy|WMYOrG<v7mfS?_?QMd-u>qep(0cj5t4JZx$s z81FM}X7t3`-JQ|V_T?+Z@J66pFXqDL?j}mxfxd$LTA+j0WOKK+-U_tBdd!^AhCN8G zA-RF%*2x;vS}0Q;a68Z?7;n#-)j!JCUNJO6n~16MOw?miMoJW_m!}0&qHKdZ+8-p+ zB$+NfnZpiUZbbSZA4pzpjbfSaGZ|$p6=gHhtS|6{a_wFfHOaGwO696N7xiy>h_GNbC8IWo!*`9Gk9s;jYZyl zAoQWhi|(I8bC749q%U{}N+G4lV$rQ%zrtD~^j0w}&o7vU(Y$OnBJL~@0(JFC3zkEk zlQvl+>H=8557Up}{TimRwFJ^P03eGy6-eDvkb0*eeFXj*q)!o$bC7x{e-osQIY@op z{0We@0Hj572rwOlo;FaT-e^@O@qx*bEbgeBE6jp&ks#m{wxhy+R6dd>63kImg_@iP z^{b4|W8j|`GU_j8bRB&EkBl|}X(}0Eqr3Z(jl^h0=aQ*Tksk^5s|j6Sg6L@oEWr0t zdhv%T{cp`uSBSra82M_Db=VObhHb`KVdh^9&@#YoQdC3cS5tguDa9DCy`0^p5wHQi zV5RiG3`>QZ%S%x`UbpHA2P1Dwi6fO57?r1{vN5+Q{N&b+g%d?#6DTa3!qXRe3TK?E a8q42Fb3TybE_|bj#+W`iOWKxi Date: Sun, 10 Jan 2021 15:20:15 +0530 Subject: [PATCH 08/10] Completed Extra Challenge --- Python-ifed.ipynb | 42 +++------------------ pokedex.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 36 deletions(-) create mode 100644 pokedex.py diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 214b7d6..76681ca 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -397,7 +397,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -448,7 +448,7 @@ ], "cell_type": "code", "metadata": {}, - "execution_count": 8, + "execution_count": 21, "outputs": [ { "output_type": "stream", @@ -479,31 +479,9 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Pokemon of Type: grass\n", - "bulbasaur,ivysaur,venusaur,oddish,gloom\n", - "\n", - "Pokemon of Type: electric\n", - "pikachu,raichu,magnemite,magneton,voltorb\n", - "\n", - "Pokemon of Type: rock\n", - "geodude,graveler,golem,onix,rhyhorn\n", - "\n", - "Pokemon of Type: electric\n", - "pikachu,raichu,magnemite,magneton,voltorb\n", - "\n", - "Pokemon of Type: ice\n", - "dewgong,cloyster,jynx,lapras,articuno\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "# Insert your code here\n", "for i in range(len(d_dmg_url)):\n", @@ -528,17 +506,9 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "============================= test session starts =============================\nplatform win32 -- Python 3.8.0, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\nrootdir: c:\\Users\\geo\\Desktop\\Python-ifed-challenge\ncollected 4 items\n\ntest_abilities.py FFFF [100%]\n\n================================== FAILURES ===================================\n____________________________ test_ability_machamp _____________________________\n\n def test_ability_machamp():\n> assert(ability(\"machamp\")==['guts', 'no-guard', 'steadfast'])\nE AssertionError: assert None == ['guts', 'no-guard', 'steadfast']\nE + where None = ability('machamp')\n\ntest_abilities.py:4: AssertionError\n---------------------------- Captured stdout call -----------------------------\n['guts', 'no-guard', 'steadfast']\n____________________________ test_ability_pikachu _____________________________\n\n def test_ability_pikachu():\n> assert(ability(\"pikachu\")==['static', 'lightning-rod'])\nE AssertionError: assert None == ['static', 'lightning-rod']\nE + where None = ability('pikachu')\n\ntest_abilities.py:7: AssertionError\n---------------------------- Captured stdout call -----------------------------\n['static', 'lightning-rod']\n___________________________ test_ability_charizard ____________________________\n\n def test_ability_charizard():\n> assert(ability(\"charizard\")==['blaze', 'solar-power'])\nE AssertionError: assert None == ['blaze', 'solar-power']\nE + where None = ability('charizard')\n\ntest_abilities.py:10: AssertionError\n---------------------------- Captured stdout call -----------------------------\n['blaze', 'solar-power']\n______________________________ test_ability_evee ______________________________\n\n def test_ability_evee():\n> assert(ability(\"eevee\")==['run-away', 'adaptability', 'anticipation'])\nE AssertionError: assert None == ['run-away', 'adaptability', 'anticipation']\nE + where None = ability('eevee')\n\ntest_abilities.py:13: AssertionError\n---------------------------- Captured stdout call -----------------------------\n['run-away', 'adaptability', 'anticipation']\n=========================== short test summary info ===========================\nFAILED test_abilities.py::test_ability_machamp - AssertionError: assert None ...\nFAILED test_abilities.py::test_ability_pikachu - AssertionError: assert None ...\nFAILED test_abilities.py::test_ability_charizard - AssertionError: assert Non...\nFAILED test_abilities.py::test_ability_evee - AssertionError: assert None == ...\n============================== 4 failed in 6.45s ==============================\n" - ] - } - ], + "outputs": [], "source": [ "!pytest test_abilities.py" ] diff --git a/pokedex.py b/pokedex.py new file mode 100644 index 0000000..ddfdc90 --- /dev/null +++ b/pokedex.py @@ -0,0 +1,94 @@ +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######################################################### + ddm=['',''] + ddm[0]+=tp[0] + ddm[1]+=tp[1] + + d_dmg_url=[] + tp=[] + ans1=[] + ans2=[] + cn=0 + for url in urls: + poke_type=requests.get(url).json() + for j in poke_type["damage_relations"]["double_damage_from"]: + if not cn: + ans1.append(j["name"]) + else: + ans2.append(j["name"]) + tp.append(j["name"]) + d_dmg_url.append(j["url"]) + cn+=1 + Details='' + Details="Double Damage are given by the following type: \n" + Details+="For "+str(ddm[0])+" : "+str(ans1)+"\n" + Details+="For "+str(ddm[1])+" : "+str(ans2)+"\n" + window['-OUTPUT3-'].update(Details) + + ######################################List 5 pokemon################################################### + Details='List 5 pokemons which gives the given pokemon double damage:\n' + 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 \ No newline at end of file From 8acfbacd05daee5d180b3e9b1db174555f4b833d Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 18:55:37 +0530 Subject: [PATCH 09/10] Completed Extra Challenge --fixed a small error --- Python-ifed.ipynb | 54 ++++++++++++++++++++++++++++--------------- pokedex.py | 21 +++++------------ tempCodeRunnerFile.py | 44 ++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 34 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 76681ca..6f8e5a3 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -397,14 +397,14 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 22, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "water\nflying\n" + "ghost\npoison\n" ] } ], @@ -412,7 +412,7 @@ "# Insert your code here\n", "import requests\n", "\n", - "urll = \"http://pokeapi.co/api/v2/pokemon/gyarados/\"\n", + "urll = \"http://pokeapi.co/api/v2/pokemon/gengar/\"\n", "urls=[]\n", "data = requests.get(urll).json()\n", "for i in range (2):\n", @@ -448,24 +448,23 @@ ], "cell_type": "code", "metadata": {}, - "execution_count": 21, + "execution_count": 25, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "grass\n", - "electric\n", - "steel\n", - "fire\n", - "water\n", - "ice\n", - "rock\n", - "electric\n", - "ice\n", - "fighting\n", - "bug\n", - "grass\n" + "ghost\n", + "dark\n", + "hi\n", + "hi\n", + "ground\n", + "psychic\n", + "hi\n", + "hi\n", + "hi\n", + "hi\n", + "hi\n" ] } ] @@ -479,9 +478,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "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\n", "for i in range(len(d_dmg_url)):\n", diff --git a/pokedex.py b/pokedex.py index ddfdc90..4310132 100644 --- a/pokedex.py +++ b/pokedex.py @@ -45,29 +45,20 @@ def ability(name): window['-OUTPUT2-'].update(Details) ################################DOUBLE DAMAGE######################################################### - ddm=['',''] - ddm[0]+=tp[0] - ddm[1]+=tp[1] + + Details="Double Damage are given by the following type: \n" d_dmg_url=[] - tp=[] - ans1=[] - ans2=[] cn=0 for url in urls: poke_type=requests.get(url).json() + Details+="Double Damage for "+tp[cn]+" by: " + cn+=1 for j in poke_type["damage_relations"]["double_damage_from"]: - if not cn: - ans1.append(j["name"]) - else: - ans2.append(j["name"]) + Details+=j["name"]+' ' tp.append(j["name"]) d_dmg_url.append(j["url"]) - cn+=1 - Details='' - Details="Double Damage are given by the following type: \n" - Details+="For "+str(ddm[0])+" : "+str(ans1)+"\n" - Details+="For "+str(ddm[1])+" : "+str(ans2)+"\n" + Details+='\n' window['-OUTPUT3-'].update(Details) ######################################List 5 pokemon################################################### diff --git a/tempCodeRunnerFile.py b/tempCodeRunnerFile.py index 4ffa2bd..c4b9e04 100644 --- a/tempCodeRunnerFile.py +++ b/tempCodeRunnerFile.py @@ -1 +1,43 @@ -data = response.json() \ No newline at end of file + ################################DOUBLE DAMAGE######################################################### + ddm=['',''] + ddm[0]+=tp[0] + ddm[1]+=tp[1] + + d_dmg_url=[] + tp=[] + ans1=[] + ans2=[] + cn=0 + for url in urls: + poke_type=requests.get(url).json() + for j in poke_type["damage_relations"]["double_damage_from"]: + if not cn: + ans1.append(j["name"]) + else: + ans2.append(j["name"]) + tp.append(j["name"]) + d_dmg_url.append(j["url"]) + cn+=1 + Details='' + Details="Double Damage are given by the following type: \n" + Details+="For "+str(ddm[0])+" : "+str(ans1)+"\n" + Details+="For "+str(ddm[1])+" : "+str(ans2)+"\n" + window['-OUTPUT3-'].update(Details) + + ######################################List 5 pokemon################################################### + Details='List 5 pokemons which gives the given pokemon double damage:\n' + 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() \ No newline at end of file From 6dd3d0206dc1a19434c9cedae7ad99a26bd7619c Mon Sep 17 00:00:00 2001 From: Geo Jolly <69108486+kingjuno@users.noreply.github.com> Date: Sun, 10 Jan 2021 19:13:07 +0530 Subject: [PATCH 10/10] Completed Extra Challenge --fixed a small error 2 --- Python-ifed.ipynb | 41 +++++++---------------------------------- pokedex.py | 5 ++++- test2.py | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 35 deletions(-) create mode 100644 test2.py diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 6f8e5a3..7b78831 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -397,22 +397,14 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "ghost\npoison\n" - ] - } - ], + "outputs": [], "source": [ "# Insert your code here\n", "import requests\n", "\n", - "urll = \"http://pokeapi.co/api/v2/pokemon/gengar/\"\n", + "urll = \"http://pokeapi.co/api/v2/pokemon/gyarados/\"\n", "urls=[]\n", "data = requests.get(urll).json()\n", "for i in range (2):\n", @@ -443,31 +435,12 @@ " d_dmg_url.append(j[\"url\"])\n", " for j in poke_type[\"damage_relations\"][\"half_damage_from\"]:\n", " print(j[\"name\"])\n", - "\n", - " \n" + "\n" ], "cell_type": "code", "metadata": {}, - "execution_count": 25, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "ghost\n", - "dark\n", - "hi\n", - "hi\n", - "ground\n", - "psychic\n", - "hi\n", - "hi\n", - "hi\n", - "hi\n", - "hi\n" - ] - } - ] + "execution_count": null, + "outputs": [] }, { "cell_type": "markdown", @@ -478,7 +451,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 27, "metadata": {}, "outputs": [ { diff --git a/pokedex.py b/pokedex.py index 4310132..e3a73bd 100644 --- a/pokedex.py +++ b/pokedex.py @@ -50,9 +50,11 @@ def ability(name): 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 "+tp[cn]+" by: " + Details+="Double Damage for "+tpp[cn]+" by: " cn+=1 for j in poke_type["damage_relations"]["double_damage_from"]: Details+=j["name"]+' ' @@ -63,6 +65,7 @@ def ability(name): ######################################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') diff --git a/test2.py b/test2.py new file mode 100644 index 0000000..347d40f --- /dev/null +++ b/test2.py @@ -0,0 +1,38 @@ +# #1 +# import requests + +# url = "http://pokeapi.co/api/v2/pokemon/jigglypuff/" + +# payload = "" +# response = requests.request("GET", url, data=payload) + +# data = response.json() +# print("Type 1:",data["types"][0]["type"]["name"]) +# print("Type 2:",data["types"][1]["type"]["name"]) +import requests + +url = "http://pokeapi.co/api/v2/pokemon/jigglypuff/" + +url1=(data["types"][0]["type"]["url"]) +url2=(data["types"][1]["type"]["url"]) + +payload1 = "" +payload2 = "" + +response1 = requests.request("GET", url1, data=payload1) +response2 = requests.request("GET", url2, data=payload2) + +data1 = response1.json() +data2 = response2.json() + +for i in range(len(data1["damage_relations"]["double_damage_from"])): + print(data1["damage_relations"]["double_damage_from"][i]["name"]) + +for i in range(len(data2["damage_relations"]["double_damage_from"])): + print(data2["damage_relations"]["double_damage_from"][i]["name"]) + +for i in range(len(data1["damage_relations"]["half_damage_from"])): + print(data1["damage_relations"]["half_damage_from"][i]["name"]) + +for i in range(len(data2["damage_relations"]["half_damage_from"])): + print(data2["damage_relations"]["half_damage_from"][i]["name"]) \ No newline at end of file