{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Second Assignment" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 1) Create a function called **\"even_squared\"** that receives an integer value **N**, and returns a list containing, in ascending order, the square of each of the even values, from 1 to N, including N if applicable. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 2) Using a while loop and the **input()** function, read an indefinite amount of **integers** until the number read is **-1**. After this process, print two lists on the screen: The first containing the even integers, and the second containing the odd integers. Both must be in ascending order. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 3) Create a function called **\"even_account\"** that receives a list of integers, counts the number of existing even elements, and returns this count. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 4) Create a function called **\"squared_list\"** that receives a list of integers and returns another list whose elements are the squares of the elements of the first. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 5) Create a function called **\"descending\"** that receives two lists of integers and returns a single list, which contains all the elements in descending order, and may include repeated elements. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 6) Create a function called **\"adding\"** that receives a list **A**, and an arbitrary number of integers as input. Return a new list containing the elements of **A** plus the integers passed as input, in the order in which they were given. Here is an example: \n", "\n", ">```python\n", ">>>> A = [10,20,30]\n", ">>>> adding(A, 4, 10, 50, 1)\n", "> [10, 20, 30, 4, 10, 50, 1]\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 7) Create a function called **\"intersection\"** that receives two input lists and returns another list with the values that belong to the two lists simultaneously (intersection) without repetition of values and in ascending order. Use only lists (do not use sets); loops and conditionals. See the example: \n", "\n", ">```python\n", ">>>> A = [-2, 0, 1, 2, 3]\n", ">>>> B = [-1, 2, 3, 6, 8]\n", ">>>> intersection(A,B)\n", "> [2, 3]\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 8) Create a function called **\"union\"** that receives two input lists and returns another list with the union of the elements of the two received, without repetition of elements and in ascending order. Use only lists (do not use sets); loops and conditionals. See the example: \n", "\n", ">```python\n", ">>>> A = [-2, 0, 1, 2]\n", ">>>> B = [-1, 1, 2, 10]\n", ">>>> union(A,B)\n", "> [-2, ,-1, 0, 1, 2, 10]\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 9) Generalize the **\"intersection\"** function so that it receives an indefinite number of lists and returns the intersection of all of them. Call the new function **intersection2**. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Challenge\n", "\n", "#### 10) Create a function named **\"matrix\"** that implements matrix multiplication:\n", " \n", "Given the matrices:\n", " \n", "$A_{m\\times n}=\n", "\\left[\\begin{matrix}\n", "a_{11}&a_{12}&...&a_{1n}\\\\\n", "a_{21}&a_{22}&...&a_{2n}\\\\\n", "\\vdots &\\vdots &&\\vdots\\\\\n", "a_{m1}&a_{m2}&...&a_{mn}\\\\\n", "\\end{matrix}\\right]$\n", " \n", "We will represent then as a list of lists.\n", "\n", "$A = [[a_{11},a_{12},...,a_{1n}],[a_{21},a_{22},...,a_{2n}], . . . ,[a_{m1},a_{m2},...,a_{mn}]]$\n", "\n", "The **\"matrix\"** funtion must receive two matrices $A$ e $B$ in the specified format and return $A\\times B$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }