{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# In Class Activity - Python - For loops" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Problem 0: For-loop over a dictionary" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a dictionary `colleges` that lists the city and zip (as values) for several schools in NYC (as keys)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colleges = {}\n", "colleges['NYU'] = 'New York, NY 10012'\n", "colleges['Columbia'] = 'New York, NY 10027'\n", "colleges['Fordham'] = 'Bronx, NY 10458'\n", "colleges['Brooklyn college'] = 'Brooklyn, NY 11210'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write a for-loop to iterate over the keys and return the values, printing in this format:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "![](images-python-ica-2/colleges.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Your answer goes here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Problem 1: Multiplication table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write a function `mult_table(n)` that produces the multiplication table below. Note that for each cell $c_{ij}$, its value is equal to the product of the row number $i$ and column number $j$, assuming they are numbered $1,\\dots,n$.\n", "\n", "Note, it's not necessary to get the spacing exactly as in the example, but kudos if you do!\n", "\n", "Here is what the output should look like when you run `mult_table(10)`\n", "\n", "![](images-python-ica-2/mult_table.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Your answer goes here" ] } ], "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.7.9" } }, "nbformat": 4, "nbformat_minor": 4 }