diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..852badb 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -62,15 +62,27 @@ "### Describe what each of the following means\n", "\n", "#### Production\n", - "(Insert answer here)\n", + "\n", + "Production means anything that you need to work reliably, and consistently.\n", + "Whether is a build script, or a public facing web server.\n", + "When others rely on your code, particularly folks who may not understand it (i.e. even \"smart\" developers but perhaps not in your group, but using a library you wrote), that code is production code.\n", + "software running on production servers to handle live users and data of the intended audience. Note, this is different from production quality code, which describes code that meets expectations in reliability, efficiency, etc., for production. Ideally, all code in production meets these expectations, but this is not always the case.\n", + "\n", "#### Clean \n", - "(Insert answer here)\n", + "\n", + "Readable, simple, and concise. A characteristic of production quality code that is crucial for collaboration and maintainability in software development.\n", + "\n", "#### Modular\n", - "(Insert answer here)\n", + "\n", + "Logically broken up into functions and modules. Also an important characteristic of production quality code that makes your code more organized, efficient, and reusable.\n", + "\n", "#### Module\n", - "(Insert answer here)\n", + "\n", + "A file. Modules allow code to be reused by encapsulating them into files that can be imported into other files.\n", + "\n", "#### Refactoring code\n", - "(Insert answer here)" + "\n", + "The process of restructuring existing computer code—changing the factoring—without changing its external behavior. Refactoring is intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functionality. Potential advantages of refactoring may include improved code readability and reduced complexity; these can improve the source code's maintainability and create a simpler, cleaner, or more expressive internal architecture or object model to improve extensibility. Another potential goal for refactoring is improved performance; software engineers face an ongoing challenge to write programs that perform faster or use less memory.\n" ] }, { @@ -171,7 +183,12 @@ "metadata": {}, "outputs": [], "source": [ - "# Insert your solution here" + "labels = list(df.columns)\n", + "for i in range(len(list(df.columns))):\n", + " if i==4:continue\n", + " labels[i] = labels[i].replace(' ', '_')\n", + "df.columns = labels\n", + "df.head()" ] }, { @@ -208,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -219,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -227,15 +244,23 @@ " subset_elements = f.read().split('\\n')\n", " \n", "with open('all_elements.txt') as f:\n", - " all_elements = f.read().split('\\n')\n", - " " + " all_elements = f.read().split('\\n')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 11.16912055015564 seconds\n" + ] + } + ], "source": [ "start = time.time()\n", "verified_elements = []\n", @@ -257,12 +282,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 6.100686311721802 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start = time.time()\n", + "verified_elements = []\n", "\n", + "array_sub = np.array(subset_elements)\n", + "array_all = np.array(all_elements)\n", + "\n", + "for element in array_sub:\n", + " if element in array_all:\n", + " verified_elements.append(element)\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" ] @@ -276,12 +317,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 0.024938344955444336 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", - "\n", + "start = time.time()\n", + "verified_elements = []\n", + "tuple_sub = tuple(subset_elements)\n", + "tuple_all = tuple(all_elements)\n", + "verified_elements = set(tuple_all) & set(tuple_sub)\n", "print(len(verified_elements))\n", "print('Duration: {} seconds'.format(time.time() - start))" ] @@ -386,11 +439,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Insert your code here" + "import requests\n", + "import pokebase as pb\n", + "pikachu = pb.APIResource('pokemon', 'pikachu')\n", + "print(pikachu.types[0].type.name)" ] }, { @@ -404,11 +460,17 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Insert your code here" + "import requests\n", + "import pokebase as pb\n", + "electric = pb.APIResource('type', 'electric')\n", + "for i in range(len(electric.damage_relations.double_damage_from)):\n", + " print(electric.damage_relations.double_damage_from[i].name)\n", + "for i in range(len(electric.damage_relations.half_damage_from)):\n", + " print(electric.damage_relations.half_damage_from[i].name)" ] }, { @@ -420,11 +482,21 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Insert your code here" + "import requests\n", + "import pokebase as pb\n", + "times = 0\n", + "electric = pb.APIResource('type', 'electric')\n", + "typeofpoke = electric.damage_relations.double_damage_from[0].name\n", + "while times != 5:\n", + " for i in range(1,1119):\n", + " pikachu = pb.APIResource('pokemon', i)\n", + " if pikachu.types[0].type.name == typeofpoke:\n", + " print(pikachu.name)\n", + " times=times+1" ] }, { @@ -438,24 +510,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "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" - ] - } - ], + "outputs": [], "source": [ "!pytest test_abilities.py" ] @@ -515,9 +572,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.3" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..05d5615 --- /dev/null +++ b/ability.py @@ -0,0 +1,9 @@ +import requests +import pokebase as pb + +def ability(pokemonname): + abilities = [] + pokemonname = pb.APIResource('pokemon', pokemonname) + for i in range(len(pokemonname.abilities)): + abilities.append(pokemonname.abilities[i].ability.name) + return abilities \ No newline at end of file diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..149f826 --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,5 @@ +import math +def nearsqr(input): + if input<0: + return 0 + return(math.floor(math.sqrt(input))**2) diff --git a/step_4.py.py b/step_4.py.py new file mode 100644 index 0000000..acba64a --- /dev/null +++ b/step_4.py.py @@ -0,0 +1,48 @@ +"""This is a python program which imports data from a all_elements.txt file and finds the required elements ie. same as the ones in subset_elements.txt and append it into a new list. +This task was optimised by different functions and the time taken by each task is displayed after it completes the running process. +The numpyfunc() as the name indicates use numpy to speed up the process and datastructuremethod() uses the tuple datastructure to make things faster. +and the givenfunc() is the one with the slowest speed +This needs the import of various modules like time to measure time taken, numpy to introduce numpy array, and pandas to handle the data""" +import time +import pandas as pd +import numpy as np +#opening the text file in python and arrangement as well as storing it to a variable +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') +#definition of the numpyfunc() function +def numpyfunc(): + start = time.time() + verified_elements = [] + array_sub = np.array(subset_elements) + array_all = np.array(all_elements) + + for element in array_sub: + if element in array_all: + verified_elements.append(element) + print(len(verified_elements)) + print('Duration: {} seconds'.format(time.time() - start)) +#definition of the datastructuremethod function +def datastructuremethod(): + start = time.time() + verified_elements = [] + tuple_sub = tuple(subset_elements) + tuple_all = tuple(all_elements) + verified_elements = set(tuple_all) & set(tuple_sub) + print(len(verified_elements)) + print('Duration: {} seconds'.format(time.time() - start)) +#definition of the givenfunc function +def givenfunc(): + 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)) + +# the main function of the file +numpyfunc() +datastructuremethod() +givenfunc()