From d63b5317654da7176b7aa3f38ca65032930b9145 Mon Sep 17 00:00:00 2001 From: Akshita Date: Sun, 10 Jan 2021 20:55:59 +0530 Subject: [PATCH] python-ifed --- Python-ifed.ipynb | 116 ++++++++++++++---- __pycache__/ability.cpython-38.pyc | Bin 0 -> 525 bytes __pycache__/nearest_square.cpython-38.pyc | Bin 0 -> 380 bytes ...test_abilities.cpython-38-pytest-6.2.1.pyc | Bin 0 -> 1980 bytes ...nearest_square.cpython-38-pytest-6.2.1.pyc | Bin 0 -> 2026 bytes ability.py | 11 ++ nearest_square.py | 11 ++ step_4.py | 54 ++++++++ 8 files changed, 169 insertions(+), 23 deletions(-) create mode 100644 __pycache__/ability.cpython-38.pyc create mode 100644 __pycache__/nearest_square.cpython-38.pyc create mode 100644 __pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc create mode 100644 __pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc create mode 100644 ability.py create mode 100644 nearest_square.py create mode 100644 step_4.py diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..ffe94fe 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -38,7 +38,7 @@ "\n", "1. Install git CLI tool\n", "1. Configure git CLI\n", - "1. Create a GitHub account if you already have not \n", + "1. Create a GitHub account if you haven't already\n", "1. Clone the repo that contains this repository\n", "1. Now you are in master branch\n", "1. Create a new branch with your name as the branch name and continue\n", @@ -62,15 +62,20 @@ "### Describe what each of the following means\n", "\n", "#### Production\n", - "(Insert answer here)\n", + "Production code is a software running on production servers to handle live users and data of the intended audience.\n", + "\n", "#### Clean \n", - "(Insert answer here)\n", + "A code that is efficient, readable, and easy to maintain. A clean code is easy to read, whether that reader is the original author of the code or somebody else. It is easy to understand and change thereby easing the abiliy to extend and refactor the code. \n", + "\n", "#### Modular\n", - "(Insert answer here)\n", + "Modular means the code is logically broken up into functions and modules. Modular programming advocates that software should be composed of separate, interchangeable components called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish this.\n", + "\n", "#### Module\n", - "(Insert answer here)\n", + "Module is a file. Modules allow the code to be reused by encapsulating them into files that can be imported into other files.\n", + "A module, contains code and data to implement a particular aspect of the program and is usually packaged in a single unit so that it can be easily deployed.\n", + "\n", "#### Refactoring code\n", - "(Insert answer here)" + "\"Re-factoring\" means to change the \"factoring\" of an existing code. Factoring is the process of breaking a complex problem or system into parts that are easier to conceive, understand, program, and maintain. So, refactoring a code means to make the code cleaner and redesign it in a simpler way without changing the functionality or the external behaviour of the code. " ] }, { @@ -171,7 +176,11 @@ "metadata": {}, "outputs": [], "source": [ - "# Insert your solution here" + "# Insert your solution here\n", + "import itertools \n", + "for i in itertools.chain(range(4), range(5,11)):\n", + " df.columns[i]=df.columns[i].str.replace(' ', '_')\n", + "df.head()" ] }, { @@ -262,7 +271,7 @@ "outputs": [], "source": [ "# Insert answer here\n", - "\n", + "verified_elements.append(np.intersect1d(subset_elements, all_elements))\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" ] @@ -281,7 +290,7 @@ "outputs": [], "source": [ "# Insert answer here\n", - "\n", + "verified_elements = set(subset_elements).intersection(all_elements)\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" ] @@ -330,9 +339,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\nrootdir: /home/akki/Python-ifed-challenge\ncollected 4 items \u001b[0m\n\ntest_nearest_square.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 0.01s\u001b[0m\u001b[32m ===============================\u001b[0m\n" + ] + } + ], "source": [ "! pytest test_nearest_square.py" ] @@ -388,9 +405,26 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "eevee is a normal type pokémon\n" + ] + } + ], "source": [ - "# Insert your code here" + "# Insert your code here\n", + "import requests\n", + "import json\n", + "pokemon = input(\"Enter the Pokémon: \").strip().lower()\n", + "url = f\"http://pokeapi.co/api/v2/pokemon/{pokemon}/\"\n", + "response = requests.get(url) \n", + "poke_data = json.loads(response.text)\n", + "poke_type = poke_data['types'][0]['type']['name']\n", + "type_url = poke_data['types'][0]['type']['url']\n", + "print(f'{pokemon} is a {poke_type} type pokémon')" ] }, { @@ -406,9 +440,29 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "eevee suffers no half damage\neevee is completely ineffctive against fighting type pokémons\n" + ] + } + ], "source": [ - "# Insert your code here" + "# Insert your code here\n", + "damages = requests.get(type_url)\n", + "damage_data = json.loads(damages.text)\n", + "try:\n", + " poke_half_damage = damage_data['damage_relations']['half_damage_from'][0]['name']\n", + " print(f'{pokemon} suffers little damage from {poke_half_damage} type pokémons')\n", + "except IndexError:\n", + " print(f\"{pokemon} suffers no half damage\")\n", + "try:\n", + " poke_total_damage = damage_data['damage_relations']['double_damage_from'][0]['name']\n", + " print(f'{pokemon} is completely ineffctive against {poke_total_damage} type pokémons')\n", + "except IndexError:\n", + " print(f\"{pokemon} suffers no total damage\")" ] }, { @@ -422,9 +476,25 @@ "cell_type": "code", "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "These pokémons will completely thrash poor eevee:\nkommo-o\nurshifu-single-strike-gmax\npangoro\nblaziken\nhariyama\n" + ] + } + ], "source": [ - "# Insert your code here" + "# Insert your code here\n", + "import random\n", + "poke5_url = f'https://pokeapi.co/api/v2/type/{poke_total_damage}'\n", + "names = requests.get(poke5_url) \n", + "name_poke = json.loads(names.text)\n", + "print(f'These pokémons will completely thrash poor {pokemon}:')\n", + "lists = random.sample(name_poke['pokemon'],5)\n", + "for i in range(5):\n", + " print(lists[i]['pokemon']['name'])" ] }, { @@ -438,21 +508,21 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "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", + "platform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\n", + "rootdir: /home/akki/Python-ifed-challenge\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" + "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 1.18s\u001b[0m\u001b[32m ===============================\u001b[0m\n" ] } ], @@ -515,7 +585,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.5-final" } }, "nbformat": 4, diff --git a/__pycache__/ability.cpython-38.pyc b/__pycache__/ability.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b3cb5633ca7e4cd60974ad33bced59dd16e1beb8 GIT binary patch literal 525 zcmYjO&r2gQ6n<}#nNDQ|4|)*x~Qp!*AUmy*>d zF*Z{zS5T4o1p$1w+d;$+b4mIG(gH%Dh79seTO9|bz3E3odcZ0O(N#CP-^p*A` zcz!APXq6oK#Z7k}`~$H`PgVc` 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..79be03853e58c781508650f82b085aacfaf19141 GIT binary patch literal 1980 zcmds2Igb-D6t?HeB%57{Yk_VXB&Nt-+!BjGhz22q#8FH$^2Sawisz8+up}f6P*NaT zD2RlR@|UKi;wP{b@6Ci&f&d9Rn8?rX@Yv4xzW3(w>S}|)^ZMP_=q)AWGa8GJ1;$Mn z`Ys4gIF%%%%7hzFgG}TNP?9w zuphY}(4xlnV;P%a8y(*t50n~=+c5Me5S&hkA!G8APAIqVh^{@c#&m4;t%*Ih^;<(f zSlk`k9m+lQcdV(yYsUWIOiAC<_aN>XGNtMXXdY^*1#!^FpqDe9&(@T3|Gl$LCJtVD z?8Fpw*WhY@>`v)R`T{_3$OH$40e9g9|JMDmmauk@C3)y{2S$(lG;4JSO!2U;jbOaP zw3*REYj1BxN89Jl=fjJEZakkW8+#k5Z3p^1&bxsQ8k3E^%6lcy3iB~@LL1hg*hO&> z#g)S~rnOL}+~8WE3vgbW)yp@E#?5?agfPlvRXa;^rbN+%aI`;&rHNBr zcrt?(x;PW*UN(@tTpD#{w$EggvP2a1NVAT>9g4ME<*9L&-cc%3#fhkssf3wGJj*3Z znSsd63s>-j>Vi9q#)U=W@}hC6GOFFKhUFD2V`qCt)CmCMaCfVhC1Q*9`|;L;q3LC5 zEA9y1f&@q@(yrL5{&dN(Sm@1sSe#sN4WoIoY~<)T2EDJ(*TRj7OvbrgtEiG3wbg82iY^E2?}1w{Qt zMAsqqe;`^1rm1*@L5$}$m(g8n0cRiSoo~pwVqAaiC%Y4f4oU)aE{gAKI$0u%jp}0)=T)xcfp)VP{iiVfojSj1Q!^0bgdK O@l2l_Cr!(@@%IgprraI? literal 0 HcmV?d00001 diff --git a/__pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc b/__pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e3b038d32afeb498002f73cc5499d063449b7325 GIT binary patch literal 2026 zcmd6o&2Q5%6u@oANz-;K--7`{6$ptO_R+DiO=4&W!2zKO3BjS4D9kCVmL|o{1RcqR z?Z}BUhxJ(gq+B`mU)YKFoOa5ffZ#+bKR>_cIQDx#zrLKFt`K+*Zyvi2CFC0piVuUq zCN%XFgdlOG=wX4?v6>d>hTw;!SrVqOptnUy*wB|nSyZ5}2>OCJ z)gi1$wj7$(Lf@0Vie2?~50q`Rj~@$^60}Fq)DZ|lQxcPe9MF^sma>E9s z->9Ru=%_o`FFDGor1g#5y6Py2VIT0!fH^3Znjn@@tRB}qrFB;PzyX^&mEB&tAjyhckZ8imN_w`;oh})sctRR9JD!byUooFu*daC;-h+cbv z8+si-E4#{T`M5$>d#JzKj>5-MMl!qLwj$Z_V%LA)4ZP5c!85S3Dt;l~V52y=TO8bL z7N)J_gM78Mrru&cXetH>FAmVp|;8z$Rf(fZY+5toW0TPb@ zvcv!odBW9afCNG08bq-F0OB+7=ODg9=q7>)0HQB3PCzs@h^7Y78i8m{0FeQVJT=BJ zPQi{PTx=o{ONZ_^5V(~wi=Y%(ockHZwGoUCmt|Z9s|9knf?{p|OaaCQ;N0ZhUSm;C z+7cwXlMX(aSdi>mnUU3Y%JmF)I|`OQ|rg9-T?cl ztp2{RKu&)uESN_MSsfP^{)fWCb^az57IRcsEK&N4!eVa?bpr695`ok=UfQTtQRqx# z;N=Voyf}rpO}q)~xX!O`LLGd65wria7$btivmiA8{}8yDNx&`L#a#RA zX(fI?n|1TrJfB|~sF(B7e<#~9)Y%hLRvOu44fl+H1G*$hBv{r_;Od3!>OAYKVc+jW UVlVI?;B{AsgH6tpDQ4^6cjTAfC;$Ke literal 0 HcmV?d00001 diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..7f34e8e --- /dev/null +++ b/ability.py @@ -0,0 +1,11 @@ +import requests +import json +def ability(name): + url = f"https://pokeapi.co/api/v2/pokemon/{name}/" + response = requests.get(url) + data = json.loads(response.text) + abilities = [] + for i in range(len(data['abilities'])): + s = data['abilities'][i]['ability']['name'] + abilities.append(str(s)) + return(abilities) diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..132e377 --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,11 @@ +import math +def nearest_square(n): + try: + lim=int(math.pow(n,0.5)) + return(int(math.pow(lim,2))) + except ValueError: + return(0) + + + + diff --git a/step_4.py b/step_4.py new file mode 100644 index 0000000..c6e2948 --- /dev/null +++ b/step_4.py @@ -0,0 +1,54 @@ +import numpy as np + +def intersection_numpy(list1,list2): + """Find the overalapping values of two lists. + + Makes use of the NumPy library to find the intersection of + the lists. + + Parameters + ---------- + list1 (array_like) : First list + list2 (array_like) : Second list + + Returns + ------- + A numpy.ndarray datatype containing the common elements of the lists + + Note + ---- + NumPy is not a part of the Python Standard Library,so + it must be installed separately using Pip before using it in your code. + Deatiled instrucions for installing NumPy can be found at: https://numpy.org/install/ + """ + return(np.intersect1d(list1, list2, assume_unique=False)) + +def intersection_datatype(list1, list2): + """Find the overlapping values of two lists. + + Makes use of Python's datastructure, sets to find intersection of the + lists. + + Parameters + ---------- + list1 (array_like) : First list + list2 (array_like) : Second list + + Returns + ------- + A set datatype containing the common elements of the lists + """ + return(set(list1)&set(list2)) + +A=[1,2,3,4,5,6,7,8,9,10] +B=[2,4,6,12] +C=intersection_numpy(A,B) +D=intersection_datatype(A,B) +print(f"The function 'intersection_numpy' returns a {type(C)} containing the common elements of the lists {A} and {B}:\n") +print(C,'\n') +print(f"The function 'intersection_datatype' returns a {type(D)} containing the common elements of the lists {A} and {B}:\n") +print(D) + + + +