{
 "metadata": {
  "name": "",
  "signature": "sha256:7cb05a28e7ffaf35858d238ed32ee5850136dba10511258d20543dca08f1609c"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 12 - Character, C-String, and C++ String Class\n",
      "Functions"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.1, page no. 262"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "ch = 'a'\n",
      "\n",
      "while(ch != 'Q' and ch != 'q'):\n",
      "    print \"Press Q or q to quit, any other key to continue: \",\n",
      "    ch = raw_input()\n",
      "    if(ch != 'Q' and ch != 'q'):\n",
      "        print \"You want to continue? \"\n",
      "    else:\n",
      "        print \"You quit\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Press Q or q to quit, any other key to continue: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "r\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " You want to continue? \n",
        "Press Q or q to quit, any other key to continue: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "q\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " You quit\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.2, page no. 264"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "ch = 'a'\n",
      "\n",
      "while(ch != 'Q' and ch != 'q'):\n",
      "    print \"Press Q or q to quit, any other key to continue: \",\n",
      "    ch = raw_input()\n",
      "    if(ch != 'Q' and ch != 'q'):\n",
      "        print \"You want to continue? \"\n",
      "    else:\n",
      "        print \"You quit\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Press Q or q to quit, any other key to continue: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "t\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " You want to continue? \n",
        "Press Q or q to quit, any other key to continue: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "q\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " You quit\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.3, page no. 266"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "ch = 'a'\n",
      "\n",
      "while(ch != 'Q' and ch != 'q'):\n",
      "    print \"Press Q or q to quit, any other key to continue: \",\n",
      "    ch = raw_input()\n",
      "    if(ch != 'Q' and ch != 'q'):\n",
      "        print \"You want to continue? \"\n",
      "    else:\n",
      "        print \"You quit\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Press Q or q to quit, any other key to continue: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "q\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " You quit\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.4, page no. 268"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "ch = 'a'\n",
      "\n",
      "while(ch != 'Q' and ch != 'q'):\n",
      "    print \"Press Q or q to quit, any other key to continue: \",\n",
      "    ch = raw_input()\n",
      "    if(ch != 'Q' and ch != 'q'):\n",
      "        print \"You want to continue? \"\n",
      "    else:\n",
      "        print \"You quit\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Press Q or q to quit, any other key to continue: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "u\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " You want to continue? \n",
        "Press Q or q to quit, any other key to continue: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "q\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " You quit\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.5, page no. 269"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "name = []\n",
      "print \"Enter course number: \",\n",
      "courseNum = int(raw_input())\n",
      "print \"Enter your name: \",\n",
      "name = raw_input()\n",
      "print \"Course number is: \", courseNum\n",
      "print \"Your name is: \", name"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter course number: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "321\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Enter your name: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Jeff\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Course number is:  321\n",
        "Your name is:  Jeff\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.6, page no. 271"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "name = []\n",
      "print \"Enter course number: \",\n",
      "courseNum = int(raw_input())\n",
      "print \"Enter your name: \",\n",
      "name = raw_input()\n",
      "print \"Course number is: \", courseNum\n",
      "print \"Your name is: \", name"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter course number: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "222\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Enter your name: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Jeff\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Course number is:  222\n",
        "Your name is:  Jeff\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.7, page no. 273"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "ch = 'a'\n",
      "while(ch != 'Q'):\n",
      "    print \"Press Q or q to quit, any other key to continue: \",\n",
      "    ch = raw_input()\n",
      "    ch = ch.upper()\n",
      "    if(ch != 'Q'):\n",
      "        print \"You want to continue? \"\n",
      "    else:\n",
      "        print \"You quit\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Press Q or q to quit, any other key to continue: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "q\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " You quit\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.8, page no. 280"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "print \"Enter first string: \",\n",
      "str1 = raw_input()\n",
      "print \"Enter second string: \",\n",
      "str2 = raw_input()\n",
      "if (str1 == str2):\n",
      "    print \"The two Cstrings are equal\"\n",
      "elif (str1 > str2):\n",
      "    print \"The first Cstring is larger\"\n",
      "else:\n",
      "    print \"The second Cstring is larger\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter first string: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Jeff\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Enter second string: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Kent\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The second Cstring is larger\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 12.9, page no. 281"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import sys\n",
      "\n",
      "print \"Enter an integer: \",\n",
      "input = raw_input()\n",
      "for x in input:\n",
      "    if (x == 0):\n",
      "        if (not(x.isdigit()) and x != '-'):\n",
      "            sys.exit()\n",
      "    else:\n",
      "        if(not(x.isdigit())):\n",
      "            sys.exit()\n",
      "num = int(input)\n",
      "print num"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter an integer: "
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "567\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " 567\n"
       ]
      }
     ],
     "prompt_number": 1
    }
   ],
   "metadata": {}
  }
 ]
}