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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
{
"metadata": {
"name": "",
"signature": "sha256:e0e8d285e21d88c99025668fa4fa5ab37c188ffb30c516ae4e90ff1d9747226e"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 5: Selection Statements"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example broker.c on Page 81"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def main():\n",
" commission=0.0 #variable declaration\n",
" value=float(raw_input(\"Enter value of trade: \")) #accepting the trade value\n",
" \n",
" #calculating commission according to the value of trade\n",
" if(value < 2500.00):\n",
" commission = 30.00 + 0.017 * value\n",
" elif (value < 6250.00):\n",
" commission = 56.00 + 0.0066 * value\n",
" elif (value < 20000.00):\n",
" commission = 76.00 + 0.0034 * value\n",
" elif (value < 50000.00):\n",
" commission = 100.00 + 0.0022 * value\n",
" elif (value < 500000.00):\n",
" commission = 155.00 + 0.0011 * value\n",
" else:\n",
" commission = 255.00 + 0.0009 * value\n",
" \n",
" if (commission < 39.00):\n",
" commission = 39.00\n",
" \n",
" print \"Commission: $%0.2f\" % commission #printing the value of commission\n",
"\n",
"if __name__=='__main__':\n",
" main()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"stream": "stdout",
"text": [
"Enter value of trade: 7000.00\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Commission: $99.80\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example on Page 83"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def main():\n",
" #variable declaration\n",
" i=1\n",
" j=2\n",
" \n",
" if(i>j): #k=i>j?i:j\n",
" k=i \n",
" else: \n",
" k=j #k is now 2\n",
" \n",
" if(i>=0): #k=(i>=0?i:0)+j\n",
" k=i+j #k is now 3\n",
" else:\n",
" k=0+j\n",
"if __name__=='__main__':\n",
" main()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example date.c on Page 89"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def main():\n",
" date=raw_input(\"Enter date (mm/dd/yy): \") #accepting the date in mm/dd/yy format\n",
" date1=date.split(\"/\")\n",
" #day, moth and year separation\n",
" day=int(date1[1])\n",
" month= int(date1[0])\n",
" year=int(date1[2])\n",
" \n",
" #printing day as an ordinal number\n",
" print \"Dated this\", day,\n",
" if (day==1 or day==21 or day==31):\n",
" print \"st\",\n",
" elif (day==2 or day==22):\n",
" print \"nd\",\n",
" elif (day==3 or day==23):\n",
" print \"rd\",\n",
" else:\n",
" print \"th\",\n",
" print \"day of\",\n",
" \n",
" #printing month\n",
" if (month==1):\n",
" print \"January\",\n",
" elif(month==2):\n",
" print \"February\",\n",
" elif(month==3):\n",
" print \"March\",\n",
" elif(month==4):\n",
" print \"April\",\n",
" elif(month==5):\n",
" print \"May\",\n",
" elif(month==6):\n",
" print \"June\",\n",
" elif(month==7):\n",
" print \"July\",\n",
" elif(month==8):\n",
" print \"August\",\n",
" elif(month==9):\n",
" print \"September\",\n",
" elif(month==10):\n",
" print \"October\",\n",
" elif(month==11):\n",
" print \"November\",\n",
" elif(month==12):\n",
" print \"December\",\n",
" \n",
" #printing year\n",
" print \", 20%0.2d.\" % year\n",
" \n",
"if __name__=='__main__':\n",
" main()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"stream": "stdout",
"text": [
"Enter date (mm/dd/yy): 7/19/14\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Dated this 19 th day of July , 2014.\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
|