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
|
{
"metadata": {
"name": "Chapter XIX"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 19: Object-oriented programming"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Program 19.1, Page number: 414"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class Fraction:\n",
" def __init__(self): #Class constructor\n",
" self.numerator=0\n",
" self.denominator=0\n",
"\n",
"def main():\n",
"\n",
" #Creating instance\n",
" myFract=Fraction()\n",
" myFract.numerator=1\n",
" myFract.denominator=3\n",
"\n",
" print(\"The Fraction is {0}/{1}\".format(myFract.numerator,myFract.denominator))\n",
"\n",
"if __name__=='__main__':\n",
" main()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The Fraction is 1/3\n"
]
}
],
"prompt_number": 1
}
],
"metadata": {}
}
]
}
|