{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 3: Conditionals & Exceptions (Review Questions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The questions below assume that you have read [Chapter 3 ](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/main/03_conditionals/00_content.ipynb).\n", "\n", "Be concise in your answers! Most questions can be answered in *one* sentence." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Essay Questions " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q1**: What is the **singleton** design pattern? How many objects does the expression `[True, False, True, False]` generate in memory?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q2**: What do we mean when we talk about **truthy** and **falsy** expressions?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q3**: Describe in your own words the concept of **short-circuiting**! What does it imply for an individual sub-expression in a boolean expression?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q4**: Explain how the conceptual difference between a **statement** and an **expression** relates to the difference between a **conditional statement** and a **conditional expression**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q5**: Why is the use of **temporary variables** encouraged in Python?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q6**: What does the `finally`-clause enforce in this code snippet? How can a `try` statement be useful *without* an `except`-clause?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```python\n", "try:\n", " print(\"Make a request to a service on the internet\")\n", "finally:\n", " print(\"This could be clean-up code\")\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## True / False Questions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Motivate your answer with *one short* sentence!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q7**: The objects `True`, `False`, and `None` represent the idea of *yes*, *no*, and *maybe* answers in a natural language.\n", "\n", "Hint: you also respond with a code cell." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q8**: The `try` statement is useful for handling **syntax** errors." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] } ], "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.12.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": false, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }