Files
learn-python3/notebooks/beginner/exercises/conditionals_exercise.ipynb
2018-05-05 15:06:24 +02:00

79 lines
1.7 KiB
Plaintext

{
"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('Name \"{}\" is more than 20 chars long'.format(name))\n",
" length_description = 'long'\n",
"elif ____:\n",
" print('Name \"{}\" is more than 15 chars long'.format(name))\n",
" length_description = 'semi long'\n",
"elif ____:\n",
" print('Name \"{}\" is more than 10 chars long'.format(name))\n",
" length_description = 'semi long'\n",
"elif ____:\n",
" print('Name \"{}\" is 8, 9 or 10 chars long'.format(name))\n",
" length_description = 'semi short'\n",
"else:\n",
" print('Name \"{}\" is a short name'.format(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
}