{ "metadata": { "name": "", "signature": "sha256:45bc61d4a504aede96e0e96eb94b2d58a50c1556daeba23c08d0c20f9f2bf948" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# if and if else" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **Author:** [Chris Albon](http://www.chrisalbon.com/), [@ChrisAlbon](https://twitter.com/chrisalbon)\n", "- **Date:** -\n", "- **Repo:** [Python 3 code snippets for data science](https://github.com/chrisalbon/code_py)\n", "- **Note:**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create a variable with the status of the conflict.\n", "\n", "- 1 if the conflict is active\n", "- 0 if the conflict is not active\n", "- unknown if the status of the conflict is unknwon" ] }, { "cell_type": "code", "collapsed": false, "input": [ "conflict_active = 1" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 10 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### If the conflict is active print a statement" ] }, { "cell_type": "code", "collapsed": true, "input": [ "if conflict_active == 1:\n", " print('The conflict is active.')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The conflict is active.\n" ] } ], "prompt_number": 17 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### If the conflict is active print a statement, if not, print a different statement" ] }, { "cell_type": "code", "collapsed": false, "input": [ "if conflict_active == 1:\n", " print('The conflict is active.')\n", "else:\n", " print('The conflict is not active.')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The conflict is active.\n" ] } ], "prompt_number": 18 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### If the conflict is active print a statement, if not, print a different statement, if unknown, state a third statement." ] }, { "cell_type": "code", "collapsed": false, "input": [ "if conflict_active == 1:\n", " print('The conflict is active.')\n", "elif conflict_active == 'unknown':\n", " print('The status of the conflict is unknown')\n", "else:\n", " print('The conflict is not active.')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The conflict is active.\n" ] } ], "prompt_number": 19 } ], "metadata": {} } ] }