{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 2\n", "(Prof. Carlos J. Costa)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**1)** Construct a list (shoppingList) including 'potatoes', 'carrots', 'cod' and 'sprouts’" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**2)** Get the second and the last element of the list" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "#Code here\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**3)** Iterate though the list in order that the users see the following list of phrases: \"We should eate sprouts\", \"We should eate carrots\"..." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#Code here. \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**4)** Add the follwoing elements to the shoppingList: orange and lime \n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**5)** Remove the carrots, the first element and last element of the shoppingList list" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**6)** How many fruits are there in the shopping list " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "#Code here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**7)** Obtain the first 3 elements of the list" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Code here\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**8)** What is the result of\n", "\n", "shopping = shoppingList\n", "\n", "shoppingListCopy = shoppingList[:]\n", "\n", "print(shopping)\n", "\n", "Why?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "**9)** What is the result of\n", "\n", "shopping = shoppingList\n", "\n", "shoppingList.append(\"orange\")\n", "\n", "print(shopping)\n", "\n", "Why?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**10)** romove all the items from the shoppingList " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**11)** What is the result of, \n", "\n", "newPurchases= (\"bananas\", \"beans\", \"rice\")\n", "\n", "print (newPurchases [1])\n", "\n", "newPurchases [0] = \"apple\"\n", "\n", "Why?\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Code here\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**12)** Create a dictionary including the follwoing elements: orange, apple, pear, grape and peach. Key are 1 to 5. Iterate through key-value pair." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Code here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**13)** Create a weekList that is composed of several lists, each one corresponding to a day list. Each day list includes the groceries to buy on this day.." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "#Code here\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**14)** Delete the shoppingList list" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "#Code here\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**15)** Create a list where x is belongs to a list of values from 1 to 100 and you want to generate a new list of y.\n", "\n", "\\begin{align}\n", "y & = 3x^2+2x+4 \\\\\n", "\\end{align}\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Code here\n", "\n", "\n" ] } ], "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": 2 }