summaryrefslogtreecommitdiff
path: root/Let_us_C/chapter-4.ipynb
diff options
context:
space:
mode:
authorHardik Ghaghada2014-06-21 14:25:56 +0530
committerHardik Ghaghada2014-06-21 14:25:56 +0530
commit299711403e92ffa94a643fbd960c6f879639302c (patch)
tree009cb02ec85f4a75ac7b64239751f15361df2bfe /Let_us_C/chapter-4.ipynb
parente1e59ca3a50d9f93e8b7bc0693b8081d5db77771 (diff)
parent7c756fcc12d21693818e58f6936cab5b7c112868 (diff)
downloadPython-Textbook-Companions-299711403e92ffa94a643fbd960c6f879639302c.tar.gz
Python-Textbook-Companions-299711403e92ffa94a643fbd960c6f879639302c.tar.bz2
Python-Textbook-Companions-299711403e92ffa94a643fbd960c6f879639302c.zip
Merge pull request #2 from debashisdeb/master
Removed Problem Statements Completely
Diffstat (limited to 'Let_us_C/chapter-4.ipynb')
-rw-r--r--Let_us_C/chapter-4.ipynb692
1 files changed, 344 insertions, 348 deletions
diff --git a/Let_us_C/chapter-4.ipynb b/Let_us_C/chapter-4.ipynb
index 75a56ab9..fcd96271 100644
--- a/Let_us_C/chapter-4.ipynb
+++ b/Let_us_C/chapter-4.ipynb
@@ -1,349 +1,345 @@
-{
- "metadata": {
- "name": "chapter-4.ipynb"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h1>Chapter 4: The Case Control Structure<h1>"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Switch - Case, Page number: 137<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Variable declaration\n",
- "i = 2\n",
- "\n",
- "#Switch case statements\n",
- "if i == 1: # case 1\n",
- " print \"I am in case 1\"\n",
- "else:\n",
- " print \"I am in case 2\"# case 2\n",
- " print \"I am in case 3\"#case 3\n",
- " print \"I am in default\"# default\n",
- " \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "I am in case 2\n",
- "I am in case 3\n",
- "I am in default\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Switch - Case, Page number: 138<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Variable declaration\n",
- "i = 2\n",
- "\n",
- "#Switch case statements\n",
- "if i == 1: # case 1\n",
- " print \"I am in case 1\"\n",
- "elif i == 2: # case 2\n",
- " print \"I am in case 2\"\n",
- "elif i == 3: #case 3\n",
- " print \"I am in case 3\"\n",
- "else: # default\n",
- " print \"I am in default\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "I am in case 2\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>The Tips and Traps a), Page number: 140<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Variable declaration\n",
- "i = 22\n",
- "\n",
- "#Switch case statements\n",
- "if i == 121: # case 121\n",
- " print \"I am in case 121\"\n",
- "elif i == 7: # case 7\n",
- " print \"I am in case 7\"\n",
- "elif i == 22: #case 22\n",
- " print \"I am in case 22\"\n",
- "else: # default\n",
- " print \"I am in default\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "I am in case 22\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>The Tips and Traps b), Page number: 140<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Variable declaration\n",
- "c = 'x'\n",
- "\n",
- "#Switch case statements\n",
- "if c == 'v': # case 'v'\n",
- " print \"I am in case v\"\n",
- "elif c == 'a': # case 'a'\n",
- " print \"I am in case a\"\n",
- "elif c == 'x': #case 'x'\n",
- " print \"I am in case x\"\n",
- "else: # default\n",
- " print \"I am in default\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "I am in case x\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>The Tips and Traps c), Page number: 141<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Input from user\n",
- "#ch = raw_input(\"Enter any of the alphabet a, b, or c : \")\n",
- "ch = 'a'\n",
- "\n",
- "#Switch case statements\n",
- "if ch == 'a' or ch == 'A' : # case 'a' and case 'A'\n",
- " print \"a as in ashar\"\n",
- "elif ch == 'b'or ch == 'B': # case 'b' and case 'B'\n",
- " print \"b as in brain\"\n",
- "elif ch == 'c'or ch == 'C': # case 'c' and case 'C'\n",
- " print \"c as in cookie\"\n",
- "else: # default\n",
- " print (\"wish you knew what are alphabets\")\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "a as in ashar\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>The Tips and Traps e) , Page number: 143<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "case or the other. If it doesn\u2019t,the compiler won\u2019t report an error.\n",
- "\n",
- "#Input from user\n",
- "#i = raw_input(\"Enter value of i \")\n",
- "i = 1\n",
- "\n",
- "#Switch case statements\n",
- "#print \"Hello\"\n",
- "if i == 1 : # case 1\n",
- " j = 10\n",
- "elif i == 2 :# case 2\n",
- " j = 20\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 3
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Goto , Page number: 146<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Input from user\n",
- "#goals = raw_input(\"Enter the number of goals scored against India: \")\n",
- "goals = 3\n",
- "\n",
- "if goals <= 5 : #goto\n",
- " print \"To err is human!\" #label sos\n",
- "else:\n",
- " print \"About time soccer players learnt C\" \n",
- " print \"and said goodbye! adieu! to soccer\" \n",
- " \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "To err is human!\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Goto , Page number: 148<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "when we want to take the control out of the loop that is contained in\n",
- "\n",
- "\n",
- "#nested for loops\n",
- "for i in range(1,4):\n",
- " for j in range(1,4):\n",
- " for k in range(1,4):\n",
- " if ( i == 3 and j == 3 and k == 3 ): #goto\n",
- " print \"Out of the loop at last!\" # label out\n",
- " break\n",
- " else:\n",
- " print i, j, k "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "1 1 1\n",
- "1 1 2\n",
- "1 1 3\n",
- "1 2 1\n",
- "1 2 2\n",
- "1 2 3\n",
- "1 3 1\n",
- "1 3 2\n",
- "1 3 3\n",
- "2 1 1\n",
- "2 1 2\n",
- "2 1 3\n",
- "2 2 1\n",
- "2 2 2\n",
- "2 2 3\n",
- "2 3 1\n",
- "2 3 2\n",
- "2 3 3\n",
- "3 1 1\n",
- "3 1 2\n",
- "3 1 3\n",
- "3 2 1\n",
- "3 2 2\n",
- "3 2 3\n",
- "3 3 1\n",
- "3 3 2\n",
- "Out of the loop at last!\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7c22324d39011030a3b150073070e5711999d5a4173c27c085bd0e0ed1d76d18"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 4: The Case Control Structure<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Switch - Case, Page number: 137<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable declaration\n",
+ "i = 2\n",
+ "\n",
+ "#Switch case statements\n",
+ "if i == 1: # case 1\n",
+ " print \"I am in case 1\"\n",
+ "else:\n",
+ " print \"I am in case 2\"# case 2\n",
+ " print \"I am in case 3\"#case 3\n",
+ " print \"I am in default\"# default\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I am in case 2\n",
+ "I am in case 3\n",
+ "I am in default\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Switch - Case, Page number: 138<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable declaration\n",
+ "i = 2\n",
+ "\n",
+ "#Switch case statements\n",
+ "if i == 1: # case 1\n",
+ " print \"I am in case 1\"\n",
+ "elif i == 2: # case 2\n",
+ " print \"I am in case 2\"\n",
+ "elif i == 3: #case 3\n",
+ " print \"I am in case 3\"\n",
+ "else: # default\n",
+ " print \"I am in default\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I am in case 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>The Tips and Traps a), Page number: 140<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable declaration\n",
+ "i = 22\n",
+ "\n",
+ "#Switch case statements\n",
+ "if i == 121: # case 121\n",
+ " print \"I am in case 121\"\n",
+ "elif i == 7: # case 7\n",
+ " print \"I am in case 7\"\n",
+ "elif i == 22: #case 22\n",
+ " print \"I am in case 22\"\n",
+ "else: # default\n",
+ " print \"I am in default\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I am in case 22\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>The Tips and Traps b), Page number: 140<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable declaration\n",
+ "c = 'x'\n",
+ "\n",
+ "#Switch case statements\n",
+ "if c == 'v': # case 'v'\n",
+ " print \"I am in case v\"\n",
+ "elif c == 'a': # case 'a'\n",
+ " print \"I am in case a\"\n",
+ "elif c == 'x': #case 'x'\n",
+ " print \"I am in case x\"\n",
+ "else: # default\n",
+ " print \"I am in default\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I am in case x\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>The Tips and Traps c), Page number: 141<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "ch = 'a'\n",
+ "\n",
+ "#Switch case statements\n",
+ "if ch == 'a' or ch == 'A' : # case 'a' and case 'A'\n",
+ " print \"a as in ashar\"\n",
+ "elif ch == 'b'or ch == 'B': # case 'b' and case 'B'\n",
+ " print \"b as in brain\"\n",
+ "elif ch == 'c'or ch == 'C': # case 'c' and case 'C'\n",
+ " print \"c as in cookie\"\n",
+ "else: # default\n",
+ " print (\"wish you knew what are alphabets\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a as in ashar\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>The Tips and Traps e) , Page number: 143<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "#Input from user\n",
+ "#i = raw_input(\"Enter value of i \")\n",
+ "i = 1\n",
+ "\n",
+ "#Switch case statements\n",
+ "#print \"Hello\"\n",
+ "if i == 1 : # case 1\n",
+ " j = 10\n",
+ "elif i == 2 :# case 2\n",
+ " j = 20\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Goto , Page number: 146<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "goals = 3\n",
+ "\n",
+ "if goals <= 5 : #goto\n",
+ " print \"To err is human!\" #label sos\n",
+ "else:\n",
+ " print \"About time soccer players learnt C\" \n",
+ " print \"and said goodbye! adieu! to soccer\" \n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To err is human!\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Goto , Page number: 148<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#nested for loops\n",
+ "for i in range(1,4):\n",
+ " for j in range(1,4):\n",
+ " for k in range(1,4):\n",
+ " if ( i == 3 and j == 3 and k == 3 ): #goto\n",
+ " print \"Out of the loop at last!\" # label out\n",
+ " break\n",
+ " else:\n",
+ " print i, j, k "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 1 1\n",
+ "1 1 2\n",
+ "1 1 3\n",
+ "1 2 1\n",
+ "1 2 2\n",
+ "1 2 3\n",
+ "1 3 1\n",
+ "1 3 2\n",
+ "1 3 3\n",
+ "2 1 1\n",
+ "2 1 2\n",
+ "2 1 3\n",
+ "2 2 1\n",
+ "2 2 2\n",
+ "2 2 3\n",
+ "2 3 1\n",
+ "2 3 2\n",
+ "2 3 3\n",
+ "3 1 1\n",
+ "3 1 2\n",
+ "3 1 3\n",
+ "3 2 1\n",
+ "3 2 2\n",
+ "3 2 3\n",
+ "3 3 1\n",
+ "3 3 2\n",
+ "Out of the loop at last!\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
} \ No newline at end of file