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 0000000..b3cb563 Binary files /dev/null and b/__pycache__/ability.cpython-38.pyc differ diff --git a/__pycache__/nearest_square.cpython-38.pyc b/__pycache__/nearest_square.cpython-38.pyc new file mode 100644 index 0000000..effbdb1 Binary files /dev/null and b/__pycache__/nearest_square.cpython-38.pyc differ 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 0000000..79be038 Binary files /dev/null and b/__pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc differ 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 0000000..e3b038d Binary files /dev/null and b/__pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc differ 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) + + + +