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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
{
"metadata": {
"name": "",
"signature": "sha256:03f3f522026b7ff6e1acac7746805bcac18faba022541a5d8a73470a897fdf7a"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 4, Some More Data Types"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Prgoram 4-1 , Page number: 47"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# An illustration of the use of floating point numbers\n",
"\n",
"# There is no loss of precision in python\n",
"a = 246.8\n",
"b = 135.79\n",
"\n",
"answer = a + b\n",
"print \"%f + %f = %f\"%(a,b,answer)\n",
"\n",
"answer = a - b\n",
"print \"%f - %f = %f\"%(a,b,answer)\n",
"\n",
"answer = a * b\n",
"print \"%f * %f = %f\"%(a,b,answer)\n",
"\n",
"answer = a / b\n",
"print \"%f / %f = %f\"%(a,b,answer)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"246.800000 + 135.790000 = 382.590000\n",
"246.800000 - 135.790000 = 111.010000\n",
"246.800000 * 135.790000 = 33512.972000\n",
"246.800000 / 135.790000 = 1.817512\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Program 4-2 , Page number: 49"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Illustration of mixed mode expressions\n",
"\n",
"a = 2\n",
"b = 12.34\n",
"\n",
"result = a * b\n",
"print \"%d * %f = %f\"%(a,b,result)\n",
"\n",
"print \"%f in scientific notation is %e\"%(result,result)\n",
"\n",
"answer = a * b\n",
"print \"%d * %f = %d\"%(a,b,answer)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"2 * 12.340000 = 24.680000\n",
"24.680000 in scientific notation is 2.468000e+01\n",
"2 * 12.340000 = 24\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Program 4-3 , Page number: 52"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"ltr_1 = \"C\"\n",
"ltr_2 = \" \"\n",
"ltr_3 = \"i\"\n",
"ltr_4 = \"s\"\n",
"ltr_5 = \"g\"\n",
"ltr_6 = \"r\"\n",
"ltr_7 = \"e\"\n",
"ltr_8 = \"a\"\n",
"ltr_9 = \"t\"\n",
"ltr_10 = \"!\"\n",
"\n",
"print \"%c%c%c%c%c%c%c%c%c%c%c\"%(ltr_1,ltr_2,ltr_3,ltr_4,ltr_2,ltr_5,ltr_6,ltr_7,ltr_8,ltr_9,ltr_10)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"C is great!\n"
]
}
],
"prompt_number": 3
}
],
"metadata": {}
}
]
}
|