{ "cells": [ { "cell_type": "markdown", "id": "d8ed7f67", "metadata": {}, "source": [ "# 1.9 Classroom Exercises" ] }, { "cell_type": "markdown", "id": "85ae7395", "metadata": {}, "source": [ "**List of exercises and estimated completion times**\n", "\n", "[1a - Python Libraries](#Exercise-1a-Python-Libraries) *5 minutes*\n", "\n", "[1b - Using Functions](#Exercise-1b-Using-Functions) *10 minutes*\n", "\n", "[1c - Operators](#Exercise-1c-Operators) *10 minutes*\n", "\n", "[1d - Maze Model](#Exercise-1d-Maze-Model) *25 minutes*\n", "\n", "[1e - The Maze Population](#Exercise-1e-The-Maze-Population) *10 minutes*\n" ] }, { "cell_type": "markdown", "id": "4ab9650f", "metadata": {}, "source": [ "## Exercise 1a Python Libraries\n", "*Relevant Sections: 1.0.2*\n", "\n", "The directory that contains this workbook also contains a `Python` file titled `draw_infinity.py`. Import it to a notebook and make the figure in the same way as `eight` was drawn in section 1.0.2" ] }, { "cell_type": "markdown", "id": "70458ec0", "metadata": {}, "source": [ "## Exercise 1b Using Functions\n", "*Relevant Sections: 1.2.1 to 1.2.5*\n", "\n", "Try to find the operator or function you need to calculate the following (the easiest way might be an internet search).\n", "\n", "What is 2 to the power 15?\n", "\n", "Convert `\"It was the best of times\"` to uppercase.\n", "\n", "Sort the list `[10, 9, 0, 20, 8, 2, 30, 7, 3]`.\n", "\n", "What is 100! ? (That is, what is the factorial of 100?) Hint: the `factorial` function is in the `math` library" ] }, { "cell_type": "markdown", "id": "d064ba13", "metadata": {}, "source": [ "## Exercise 1c Operators\n", "*Relevant Sections: 1.2.5, 1.3.3*\n", "\n", "Which of the operators `+`, `-`, `*`, and `/` do something useful with the lists `[1, 10, 100]` and `[5, 4, 7]`?\n", "\n", "What happens if you apply the operators `+`, `-`, `*`, `/` to a list and a number?\n", "\n", "What about a string and a string?" ] }, { "cell_type": "markdown", "id": "9de9ab85", "metadata": {}, "source": [ "## Exercise 1d Maze Model\n", "*Relevant Sections: 1.5.1, 1.6.1*\n", "\n", "Work with a partner to design a data structure to represent a maze using dictionaries and lists.\n", "\n", "* Each place in the maze has a name, which is a string.\n", "* Each place in the maze has one or more people currently standing at it, by name.\n", "* Each place in the maze has a maximum capacity of people that can fit in it.\n", "* From each place in the maze, you can go from that place to a few other places, using a direction like 'up', 'north', or 'sideways'\n", "\n", "Create an example instance, in a notebook, of a simple structure for your maze:\n", "\n", "* The front room can hold 2 people. James is currently there. You can go outside to the garden, or upstairs to the bedroom, or north to the kitchen.\n", "* From the kitchen, you can go south to the front room. It fits 1 person.\n", "* From the garden you can go inside to front room. It fits 3 people. Sue is currently there.\n", "* From the bedroom, you can go downstairs to the front room. You can also jump out of the window to the garden. It fits 2 people.\n", "\n", "Make sure that your model:\n", "\n", "* Allows empty rooms\n", "* Allows you to jump out of the upstairs window, but not to fly back up.\n", "* Allows rooms which people can't fit in.\n", "\n", "\n", "```python\n", "house = [ \"Your answer here\" ]\n", "```\n", "or\n", "```python\n", "house = { \"Your answer here\" }\n", "```" ] }, { "cell_type": "markdown", "id": "8643be35", "metadata": {}, "source": [ "## Exercise 1e The Maze Population\n", "*Relevant Sections: 1.5.1, 1.6.1, 1.8.1, 1.8.2*\n", "\n", "Take your maze data structure. Write a program to count the total number of people in the maze, and also determine the total possible occupants." ] } ], "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.8" } }, "nbformat": 4, "nbformat_minor": 5 }