<commit_before>{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='top'></a>If Statements\n",
      "===\n",
      "By allowing you to respond selectively to different situations and conditions, if statements open up whole new possibilities for your programs. In this section, you will learn how to test for certain conditions, and then respond in appropriate ways to those conditions."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[Previous: Introducing Functions](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/introducing_functions.ipynb) | \n",
      "[Introduction to Programming home page](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/index.ipynb) |\n",
      "[Next: Dictionaries](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/dictionaries.ipynb) | "
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Contents\n",
      "===\n",
      "- [What is an *if* statement?](#what)\n",
      "    - [Example](#example)\n",
      "- [Logical tests](#logical_tests)\n",
      "- [The if-elif...else chain](#if-elif-else)\n",
      "- [Exercises]"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='what'></a>What is an *if* statement?\n",
      "===\n",
      "An *if* statement tests for a condition, and then responds to that condition. If the condition is true, then whatever action is listed next gets carried out. You can test for multiple conditions at the same time, and respond appropriately to each condition.\n",
      "\n",
      "<a name='example'></a>Example\n",
      "---\n",
      "Here is an example that shows a number of the desserts I like. It lists those desserts, but lets you know which one is my favorite."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# A list of desserts I like.\n",
      "desserts = ['ice cream', 'chocolate', 'apple crisp', 'cookies']\n",
      "favorite_dessert = 'apple crisp'\n",
      "\n",
      "# Print the desserts out, but let everyone know my favorite dessert.\n",
      "for dessert in desserts:\n",
      "    if dessert == favorite_dessert:\n",
      "        # This dessert is my favorite, let's let everyone know!\n",
      "        print(\"%s is my favorite dessert!\" % dessert.title())\n",
      "    else:\n",
      "        # I like these desserts, but they are not my favorite.\n",
      "        print(\"I like %s.\" % dessert)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "I like ice cream.\n",
        "I like chocolate.\n",
        "Apple Crisp is my favorite dessert!\n",
        "I like cookies.\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "#### What happens in this program?\n",
      "\n",
      "- The program starts out with a list of desserts, and one dessert is identified as a favorite.\n",
      "- The for loop runs through all the desserts.\n",
      "- Inside the for loop, each item in the list is tested.\n",
      "    - If the current value of *dessert* is equal to the value of *favorite_dessert*, a message is printed that this is my favorite.\n",
      "    - If the current value of *dessert* is not equal to the value of *favorite_dessert*, a message is printed that I just like the dessert.\n",
      "    \n",
      "You can test as many conditions as you want in an if statement, as you will see in a little bit."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[top](top)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='logical_tests'></a>Logical Tests\n",
      "===\n",
      "Every if statement evaluates to *True* or *False*. *True* and *False* are Python keywords, which have special meanings attached to them. You can test for the following conditions in your if statements:\n",
      "\n",
      "- [equality](#equality) (==)\n",
      "- inequality (!=)\n",
      "- greater than (>)\n",
      "- greater than or equal to (>=)\n",
      "- less than (<)\n",
      "- less than or equal to (<=)\n",
      "- You can test if an item is **in** a list."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='equality'></a>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='equality'></a>Equality\n",
      "---\n",
      "Two items are *equal* if they have the same value. You can test for equality between numbers, strings, and a number of other objects which you will learn about later. Some of these results may be surprising, so take a careful look at the examples below."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "5==5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 3,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "3==5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "False"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'eric' == 'eric'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 8,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'Eric' == 'eric'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 9,
       "text": [
        "False"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'Eric'.lower() == 'eric'.lower()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 10,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'5' == 5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 11,
       "text": [
        "False"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'5' == str(5)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 12,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[Previous: Introducing Functions](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/introducing_functions.ipynb) | \n",
      "[Introduction to Programming home page](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/index.ipynb) |\n",
      "[Next: Dictionaries](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/dictionaries.ipynb) | "
     ]
    }
   ],
   "metadata": {}
  }
 ]
}<commit_msg>Logical tests: inequality.<commit_after>{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='top'></a>If Statements\n",
      "===\n",
      "By allowing you to respond selectively to different situations and conditions, if statements open up whole new possibilities for your programs. In this section, you will learn how to test for certain conditions, and then respond in appropriate ways to those conditions."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[Previous: Introducing Functions](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/introducing_functions.ipynb) | \n",
      "[Introduction to Programming home page](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/index.ipynb) |\n",
      "[Next: Dictionaries](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/dictionaries.ipynb) | "
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Contents\n",
      "===\n",
      "- [What is an *if* statement?](#what)\n",
      "    - [Example](#example)\n",
      "- [Logical tests](#logical_tests)\n",
      "- [The if-elif...else chain](#if-elif-else)\n",
      "- [Exercises]"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='what'></a>What is an *if* statement?\n",
      "===\n",
      "An *if* statement tests for a condition, and then responds to that condition. If the condition is true, then whatever action is listed next gets carried out. You can test for multiple conditions at the same time, and respond appropriately to each condition.\n",
      "\n",
      "<a name='example'></a>Example\n",
      "---\n",
      "Here is an example that shows a number of the desserts I like. It lists those desserts, but lets you know which one is my favorite."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# A list of desserts I like.\n",
      "desserts = ['ice cream', 'chocolate', 'apple crisp', 'cookies']\n",
      "favorite_dessert = 'apple crisp'\n",
      "\n",
      "# Print the desserts out, but let everyone know my favorite dessert.\n",
      "for dessert in desserts:\n",
      "    if dessert == favorite_dessert:\n",
      "        # This dessert is my favorite, let's let everyone know!\n",
      "        print(\"%s is my favorite dessert!\" % dessert.title())\n",
      "    else:\n",
      "        # I like these desserts, but they are not my favorite.\n",
      "        print(\"I like %s.\" % dessert)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "I like ice cream.\n",
        "I like chocolate.\n",
        "Apple Crisp is my favorite dessert!\n",
        "I like cookies.\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "#### What happens in this program?\n",
      "\n",
      "- The program starts out with a list of desserts, and one dessert is identified as a favorite.\n",
      "- The for loop runs through all the desserts.\n",
      "- Inside the for loop, each item in the list is tested.\n",
      "    - If the current value of *dessert* is equal to the value of *favorite_dessert*, a message is printed that this is my favorite.\n",
      "    - If the current value of *dessert* is not equal to the value of *favorite_dessert*, a message is printed that I just like the dessert.\n",
      "    \n",
      "You can test as many conditions as you want in an if statement, as you will see in a little bit."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[top](top)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='logical_tests'></a>Logical Tests\n",
      "===\n",
      "Every if statement evaluates to *True* or *False*. *True* and *False* are Python keywords, which have special meanings attached to them. You can test for the following conditions in your if statements:\n",
      "\n",
      "- [equality](#equality) (==)\n",
      "- [inequality](#inequality) (!=)\n",
      "- greater than (>)\n",
      "- greater than or equal to (>=)\n",
      "- less than (<)\n",
      "- less than or equal to (<=)\n",
      "- You can test if an item is **in** a list."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='equality'></a>Equality\n",
      "---\n",
      "Two items are *equal* if they have the same value. You can test for equality between numbers, strings, and a number of other objects which you will learn about later. Some of these results may be surprising, so take a careful look at the examples below.\n",
      "\n",
      "In Python, as in many programming languages, two equals signs tests for equality.\n",
      "\n",
      "**Watch out!** Be careful of accidentally using one equals sign, which can really throw things off because that one equals sign actually sets your item to the value you are testing for!"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "5==5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 3,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "3==5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "False"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'eric' == 'eric'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 8,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'Eric' == 'eric'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 9,
       "text": [
        "False"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'Eric'.lower() == 'eric'.lower()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 10,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'5' == 5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 11,
       "text": [
        "False"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'5' == str(5)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 12,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<a name='inequality'></a>Inequality\n",
      "---\n",
      "Two items are *inequal* if they do not have the same value. In Python, we test for inequality using the exclamation point and one equals sign.\n",
      "\n",
      "Sometimes you want to test for equality and if that fails, assume inequality. Sometimes it makes more sense to test for inequality directly."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "3!=5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 13,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "5!=5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 14,
       "text": [
        "False"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "'Eric' != 'eric'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 15,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[top](top)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[Previous: Introducing Functions](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/introducing_functions.ipynb) | \n",
      "[Introduction to Programming home page](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/index.ipynb) |\n",
      "[Next: Dictionaries](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/dictionaries.ipynb) | "
     ]
    }
   ],
   "metadata": {}
  }
 ]
}
{'fraction_non_alphanumeric': 0.17322619438067124, 'fraction_numerical': 0.004263693014102984, 'mean_word_length': 2.00756205819497, 'pattern_counts': {'":': 284, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5369676', 'n_tokens_mistral': 6033, 'n_tokens_neox': 5826, 'n_words': 1523}