diff options
author | kinitrupti | 2017-05-12 18:53:46 +0530 |
---|---|---|
committer | kinitrupti | 2017-05-12 18:53:46 +0530 |
commit | f270f72badd9c61d48f290c3396004802841b9df (patch) | |
tree | bc8ba99d85644c62716ce397fe60177095b303db /ANSI_C_Programming_by_Yashwant_Kanetkar/chapter4.ipynb | |
parent | 64d949698432e05f2a372d9edc859c5b9df1f438 (diff) | |
download | Python-Textbook-Companions-f270f72badd9c61d48f290c3396004802841b9df.tar.gz Python-Textbook-Companions-f270f72badd9c61d48f290c3396004802841b9df.tar.bz2 Python-Textbook-Companions-f270f72badd9c61d48f290c3396004802841b9df.zip |
Removed duplicates
Diffstat (limited to 'ANSI_C_Programming_by_Yashwant_Kanetkar/chapter4.ipynb')
-rwxr-xr-x | ANSI_C_Programming_by_Yashwant_Kanetkar/chapter4.ipynb | 390 |
1 files changed, 390 insertions, 0 deletions
diff --git a/ANSI_C_Programming_by_Yashwant_Kanetkar/chapter4.ipynb b/ANSI_C_Programming_by_Yashwant_Kanetkar/chapter4.ipynb new file mode 100755 index 00000000..3a15cce2 --- /dev/null +++ b/ANSI_C_Programming_by_Yashwant_Kanetkar/chapter4.ipynb @@ -0,0 +1,390 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:c88e4872fc4418c2962652967a7ca0a93c345eb9f3bd38488ba817f74e5fc2eb" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "CHAPTER 4: THE CASE CONTROL STRUCTURE" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:126" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "i=2\n", + "def switch(i):\n", + " return {True: 'I am in default\\n', #default case\n", + " i==1: 'I am in case1\\n',\n", + " i==2: 'I am in case2\\n',\n", + " i==3: 'I am in case3\\n',\n", + " }[True]\n", + "print switch(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "I am in case2\n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:128" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "i=22\n", + "def switch(i):\n", + " return{True: 'I am in default\\n',\n", + " i==121: 'I am in case 121\\n',\n", + " i==7: 'I am in case 7\\n',\n", + " i==22: 'I am in case 22\\n',\n", + " }[True]\n", + "print switch(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "I am in case 22\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:128-129" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "c='x'\n", + "def switch(c):\n", + " return {True: 'I am in default\\n',\n", + " c=='v': 'I am in case v\\n',\n", + " c=='a': 'I am in case a\\n',\n", + " c=='x': 'I am in case x\\n',\n", + " }[True]\n", + "print switch(c)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "I am in case x\n", + "\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:129-130" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "print \"Enter any one of the alphabets a,b,or c\"\n", + "ch=raw_input()\n", + "def casea():\n", + " print \"\"\n", + "def caseb():\n", + " print \"\"\n", + "def casec():\n", + " print \"\"\n", + "def switch(ch):\n", + " return {True: 'wish you knew what are alphabets\\n',\n", + " ch=='a' or ch=='A': 'a as in ashar\\n',\n", + " ch=='b' or ch=='B': 'b as in brain\\n',\n", + " ch=='c' or ch=='C': 'c as in cookie\\n',\n", + " }[True]\n", + "print switch(ch)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter any one of the alphabets a,b,or c\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "B\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "b as in brain\n", + "\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:130" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "print \"Enter value of i\"\n", + "i=eval(raw_input())\n", + "def switch(i):\n", + " print \"Hello\\n\" #It's python,not C :)\n", + " try:\n", + " return {1: a,\n", + " 2: b,\n", + " }[i]()\n", + " except:\n", + " print \"wrong choice\" #print message in default case\n", + "def a():\n", + " j=10\n", + " print j #print j as 10 if i=1\n", + "def b():\n", + " j=20 \n", + " print j #print j as 20 if i=2\n", + "switch(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter value of i\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello\n", + "\n", + "10\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:133" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import sys\n", + "print \"Enter the number of goals scored against india\"\n", + "goals=eval(raw_input())\n", + "if goals<=5:\n", + " print \"To err is human!\\n\"\n", + "else:\n", + " print \"About time soccer players learnt C\\n\"\n", + " print \"and said goodbye! adieu! to soccer\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the number of goals scored against india\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "7\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "About time soccer players learnt C\n", + "\n", + "and said goodbye! adieu! to soccer\n", + "\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:134-135" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "for i in range(1,4,1):\n", + " for j in range(1,4,1):\n", + " for k in range(1,4,1):\n", + " if (i==3 and j==3 and k==3):\n", + " print \"Out of the loop at last!\\n\"\n", + " else:\n", + " print \"%d %d %d\\n\" % (i,j,k)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1 1 1\n", + "\n", + "1 1 2\n", + "\n", + "1 1 3\n", + "\n", + "1 2 1\n", + "\n", + "1 2 2\n", + "\n", + "1 2 3\n", + "\n", + "1 3 1\n", + "\n", + "1 3 2\n", + "\n", + "1 3 3\n", + "\n", + "2 1 1\n", + "\n", + "2 1 2\n", + "\n", + "2 1 3\n", + "\n", + "2 2 1\n", + "\n", + "2 2 2\n", + "\n", + "2 2 3\n", + "\n", + "2 3 1\n", + "\n", + "2 3 2\n", + "\n", + "2 3 3\n", + "\n", + "3 1 1\n", + "\n", + "3 1 2\n", + "\n", + "3 1 3\n", + "\n", + "3 2 1\n", + "\n", + "3 2 2\n", + "\n", + "3 2 3\n", + "\n", + "3 3 1\n", + "\n", + "3 3 2\n", + "\n", + "Out of the loop at last!\n", + "\n" + ] + } + ], + "prompt_number": 12 + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file |