{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. `if-elif-else`\n", "Fill missing pieces (`____`) of the following code such that prints make sense." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": false }, "outputs": [], "source": [ "name = \"John Doe\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if ____:\n", " print(f'Name \"{name}\" is more than 20 chars long')\n", " length_description = \"long\"\n", "elif ____:\n", " print(f'Name \"{name}\" is more than 15 chars long')\n", " length_description = \"semi long\"\n", "elif ____:\n", " print(f'Name \"{name}\" is more than 10 chars long')\n", " length_description = \"semi long\"\n", "elif ____:\n", " print(f'Name \"{name}\" is 8, 9 or 10 chars long')\n", " length_description = \"semi short\"\n", "else:\n", " print(f'Name \"{name}\" is a short name')\n", " length_description = \"short\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": false }, "outputs": [], "source": [ "assert length_description == \"semi short\"" ] } ], "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.5.4" } }, "nbformat": 4, "nbformat_minor": 2 }