"
]
},
{
"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": [
"
Switch - Case, Page number: 138
"
]
},
{
"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": [
"
The Tips and Traps a), Page number: 140
"
]
},
{
"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": [
"
The Tips and Traps b), Page number: 140
"
]
},
{
"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": [
"
The Tips and Traps c), Page number: 141
"
]
},
{
"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": [
"
The Tips and Traps e) , Page number: 143
"
]
},
{
"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": [
"