summaryrefslogtreecommitdiff
path: root/sample_notebooks/asmitaasmita/asmitaasmita_version_backup/1_An_overview.ipynb
blob: ecf52dddef1b02101ace9913af769a4ef8dae92a (plain)
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
{
 "metadata": {
  "name": "1  An overview of C++"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 1 , Page Number: 14#\\n#This program outputs a string, two integer values, and a double floating-point value. #\ni=10\nj=20\nd=99.101\nprint ('Here are some values : %d %d %2.3f'%(i,j,d))\n     ",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Here are some values : 10 20 99.101\n"
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 3 , Page Number: 16#\n\n#Variable declaration\ni=100\n\n#Result\nprint('Enter a value: 100')\nprint 'Here\\'s your number: ',i\n\n",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Enter a value: 100\nHere's your number:  100\n"
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 4 , Page Number 16#\n\n#Variable declaration\ni=10\nf=100.12\ns='Hello World'\n\n#Result\nprint 'Enter an integer,float and string: ',i,f,s\nprint 'Here\\'s your data: ',i,f,s \n                                   ",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": " Enter an integer,float and string:  10 100.12 Hello World\nHere's your data:  10 100.12 Hello World\n"
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 5 , Page Number 17#\n\n#Variable declaration\nch='X'\n\n#Result\nprint 'Enter keys,X to stop.'\n\n#while loop\nwhile ch!='X':\n if(ch!='X'): \n  print ': ',ch\n else:\n  break",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Enter keys,X to stop.\n"
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 1 , Page Number 19#\n\n#Variable declaration\na=199\n\nprint 'Enter number to be tested: ',a\n#if loop\nif a % 2 == 0:\n#Result\n print 'Number is even'\nelse:\n print 'Number is odd'\n",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Enter number to be tested:  199\nNumber is odd\n"
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 3 ,Page Number 25#\n\n#class declaration\nclass Myclass():\n def __init__(self,c,d):\n  self.a = c\n  self.b = d\nobj = Myclass(10,99)\nobj.a,obj.b\n\n#Result\nprint obj.a\nprint obj.b",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "10\n99\n"
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 2 , Page Number 30#\n\n#DefiningFunction\ndef sum(a,b):\n return a+b\na=10\nb=40\n\n#Result\nprint 'Enter two numbers: ',a,b\nprint 'Sum is: ',sum(a,b)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Enter two numbers:  10 40\nSum is:  50\n"
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 3 , Page Number 31#\n\n#Variable declaration\ni=5\nprint 'Enter number: ',i\nfact=1\nfor j in range(i):\n fact = fact * (j+1)\n    \n#Result\nprint 'Factorial is ',fact\n",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Enter number:  5\nFactorial is  120\n"
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 4 ,Page Number 32#\n\noutcome = 'false'\n\n#if loop\nif(outcome):\n print 'true'\nelse:\n print 'false'",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "true\n"
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 2 ,Page Number 36#\n\n#Defining function\ndef get_date(day=None, month=None, year=None, as_string=None):\n\tif as_string:\n\t\tprint 'Date:', as_string\n\telse:\n\t\tif not (day and month and year):\n\t\t\traise Exception(\"Invalid Date arguments\")\n\t\tprint \"Date : %d/%d/%d\" % (month, day, year)\n\n\nif __name__ == '__main__':\n\tget_date(as_string=\"3/12/2013\")\n\tget_date(day=12, month=3, year=2013)\n",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Date: 3/12/2013\nDate : 3/12/2013\n"
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Exercise 1.3 Q3 , Page Number 18#\n\n#Variable declaration\na=4\nb=8\nd=2\nprint 'Enter two numbers: ',a,b\nif a>b:\n min=b\nelse:\n min=a\nfor d in range(d,min):\n if a % d == 0 and b % d == 0:    \n  break\nif d == min:\n print 'No common denominators ' \nelse:\n print 'The lowest common denominator is ',d\n",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Enter two numbers:  4 8\nThe lowest common denominator is  2\n"
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Ex 1 , Page Number 34#\n\nprint 'Absolute value of -10: ',abs(-10)\nprint 'Absolute value of -10L: ',abs(-10L)\nprint 'Absolute value of -10.01: ',abs(-10.01)\n\n#Defining function\ndef abs(n):\n print 'In integer abs() '\n \n\ndef abs(n):\n print 'In longs abs() '\n\ndef abs(n):\n print 'In double abs() '\n",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Absolute value of -10:  10\nAbsolute value of -10L:  10\nAbsolute value of -10.01:  10.01\n"
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Excercise 1 , Page Number 18#\n\n#Variable declaration\nhours=3\nwage=2000\n\n#Result\nprint 'Enter hours worked: ',hours\n\nprint 'Enter wage per hour: ',wage\nprint 'Pay is: $',wage*hours",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Enter hours worked:  3\nEnter wage per hour:  2000\nPay is: $ 6000\n"
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Exercise 2 , Page Number 18#\n\n#Variable declaration\nfeet = 5.0\n\n#If loop\nif(feet == 0.0):\n  print 'Wrong inpt.'\nelse:\n  print 'Enter feet :',feet\n  #Result\n  print feet*12,'inches'\n ",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Enter feet : 5.0\n60.0 inches\n"
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Exercise 1.7 Q1 , Page Number 38#\n\nimport math\n\n#Result\nprint 'Square root of 90.34 is : ',math.sqrt(90.34)\nprint 'Square root of 90L is: ',math.sqrt(90L)\nprint 'Square root of 90 is: ',math.sqrt(90)\n\n#Defining functions\ndef sqrt(n):\n print 'computing integer root '\n \n\ndef sqrt(n):\n print 'computing long root '\n\ndef sqrt(n):\n print 'computing double root '",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Square root of 90.34 is :  9.50473566176\nSquare root of 90L is:  9.48683298051\nSquare root of 90 is:  9.48683298051\n"
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "#Example 3 , Page Number 36#\n\n#Defining functions\ndef f1(a=None,b=None,c=None):\n if a:\n  print 'In f1',(a)\n else:\n  if not (b and c):\n   raise Exception(\"Invalid arguments\")\n  print 'In f1',(b,c)\nif __name__ == '__main__':\n\tf1(a=10)\n\tf1(b=10, c=20)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "In f1 10\nIn f1 (10, 20)\n"
      }
     ],
     "prompt_number": 16
    }
   ],
   "metadata": {}
  }
 ]
}