{ "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": {} } ] }