1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
{
"metadata": {
"name": "ch4"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": "Chapter 4 : Conditionals and recursion"
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "example 4.1 page no :34"
},
{
"cell_type": "code",
"collapsed": false,
"input": "'''\nexample 4.1 page no :34\n'''\n\ndef printParity (x):\n if (x%2 == 0):\n print \"x is even\" \n else:\n print \"x is odd\" \n\nprintParity (17)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "x is odd\n"
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "example 4.2 page no :36"
},
{
"cell_type": "code",
"collapsed": false,
"input": "'''\nexample 4.2 page no :36\n'''\nimport math\n\ndef printLogarithm (x):\n if (x <= 0.0):\n print \"Positive numbers only, please.\" \n return;\n result = math.log(x);\n print \"The log of x is \" , result;\n\nprintLogarithm(-1)\nprintLogarithm(5)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "Positive numbers only, please.\nThe log of x is 1.60943791243\n"
}
],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "example 4.3 page no : 37"
},
{
"cell_type": "code",
"collapsed": false,
"input": "'''\nexample 4.3 page no : 37\n'''\n\ndef countdown (n):\n if (n == 0):\n print \"Blastoff!\" \n else:\n print n\n countdown (n-1)\n\ncountdown(5)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "5\n4\n3\n2\n1\nBlastoff!\n"
}
],
"prompt_number": 3
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "example 4.4\n"
},
{
"cell_type": "code",
"collapsed": false,
"input": "'''\nexample 4.4\n'''\nimport math\ndef printLogarithm(x):\n if (x <= 0.0):\n print \"Positive numbers only, please.\" << endl;\n return;\n result = math.log(x)\n print \"The log of x is \" , result;\n\ndef countdown (n) :\n if (n == 0):\n print \"Blastoff!\"\n else:\n print n\n countdown (n-1);\n\n\ncountdown (3);\nprintLogarithm(10)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "3\n2\n1\nBlastoff!\nThe log of x is 2.30258509299\n"
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": "",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
|