{ "metadata": { "name": "", "signature": "sha256:6ea814e96c295059ddb0aad4b5a377c09418fa7cc1e6d2961f547bbd944649cf" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# if Statement\n", "\n", "- **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:** Based on: A Byte of Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import the random module." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import random" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create a variable of the true number of deaths of an event." ] }, { "cell_type": "code", "collapsed": false, "input": [ "deaths = 6" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create a variable that randomly create a integer between 0 and 10." ] }, { "cell_type": "code", "collapsed": false, "input": [ "guess = random.randint(0,10)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### if guess equals deaths" ] }, { "cell_type": "code", "collapsed": false, "input": [ "if guess == deaths:\n", " # then print this\n", " print('Correct!')\n", "# else if guess is lower than deaths\n", "elif guess < deaths:\n", " # then print this\n", " print('No, it is higher.')\n", "# if guess is none of the above\n", "else:\n", " # print this\n", " print('No, it is lower')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Correct!\n" ] } ], "prompt_number": 6 } ], "metadata": {} } ] }