{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#1: Numbers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.1, Page number 1.12" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "quotient is 381.097560976\n", "remainder is 4\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "D=41; #divisor\n", "d=15625; #dividend\n", "\n", "#Calculation\n", "q=d/D; #quotient\n", "r=d%D; #remainder\n", "\n", "#Result\n", "print \"quotient is\",q\n", "print \"remainder is\",r" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.2, Page number 1.12" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "divisor is 459.0\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "D=397246; #dividend\n", "r=211; #remainder\n", "q=865; #quotient\n", "\n", "#Calculation\n", "d=(D-r)/q; #divisor\n", "\n", "#Result\n", "print \"divisor is\",d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.4, Page number 1.13" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "least number to be subtracted is 125\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "d=87375; #dividend\n", "D=698; #divisor\n", "\n", "#Calculation\n", "r=d%D; #remainder\n", "\n", "#Result\n", "print \"least number to be subtracted is\",r" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.5, Page number 1.13" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "least number to be added is 58\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration\n", "d=49123; #dividend\n", "D=263; #divisor\n", "\n", "#Calculation\n", "r=d%D; #remainder\n", "l=D-r; #least number to be added\n", "\n", "#Result\n", "print \"least number to be added is\",l" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.6, Page number 1.13" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "required number is 980\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration \n", "d=999; #dividend\n", "D=35; #divisor\n", "\n", "#Calculation\n", "r=d%D; #remainder\n", "rn=d-r; #required number\n", "\n", "#Result\n", "print \"required number is\",rn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.7, Page number 1.13" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "required number is 112\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration \n", "d=100; #dividend\n", "D=14; #divisor\n", "\n", "#Calculation\n", "r=d%D; #remainder\n", "rn=d+D-r; #required number\n", "\n", "#Result\n", "print \"required number is\",rn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.8, Page number 1.13" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "required remainder is 8\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration \n", "d=602; #dividend\n", "D=14; #divisor\n", "rl=36; #remainder\n", "\n", "#Calculation\n", "k=d/D; #quotient\n", "rs=rl-(2*D); #required remainder\n", "\n", "#Result\n", "print \"required remainder is\",rs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.9, Page number 1.13" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "required remainder is 39\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration \n", "d=357; #dividend\n", "D=17; #divisor\n", "rs=5; #remainder\n", "\n", "#Calculation\n", "k=d/D; #quotient\n", "rl=(2*D)+rs; #required remainder\n", "\n", "#Result\n", "print \"required remainder is\",rl" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.11, Page number 1.25" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "binary equivalent of 30 is 0b11110\n", "binary equivalent of 27 is 0b11011\n", "binary equivalent of 41 is 0b101001\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration \n", "a=30;\n", "b=27;\n", "c=41; #numbers in decimal form\n", "\n", "#Calculation\n", "ba=bin(a); #binary equivalent of 30\n", "bb=bin(b); #binary equivalent of 27\n", "bc=bin(c); #binary equivalent of 41\n", "\n", "#Result\n", "print \"binary equivalent of 30 is\",ba\n", "print \"binary equivalent of 27 is\",bb\n", "print \"binary equivalent of 41 is\",bc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Example number 1.12, Page number 1.26" ] }, { "cell_type": "code", "execution_count": 44, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "result of 10110-1011 is 0b1011\n", "result of 1001+1010 is 0b10011\n", "result of 101*100 is 0b10100\n", "result of 1100/11 is 0b100\n", "result of 101+1100/10 is 0b1011\n" ] } ], "source": [ "#importing modules\n", "import math\n", "from __future__ import division\n", "\n", "#Variable declaration \n", "a='10110'\n", "b='1011'\n", "c='1001'\n", "d='1010'\n", "e='101'\n", "f='100'\n", "g='1100'\n", "h='11'\n", "i='101'\n", "j='1100'\n", "k='10'\n", "\n", "#Calculation\n", "a_b=bin(int(a,2)-int(b,2)); #result of 10110-1011\n", "c_d=bin(int(c,2)+int(d,2)); #result of 1001+1010\n", "e_f=bin(int(e,2)*int(f,2)); #result of 101*100\n", "gh1=int(g,2);\n", "gh2=int(h,2);\n", "gh=int(gh1/gh2); \n", "g_h=bin(gh); #result of 1100/11\n", "j_k=bin(int(int(j,2)/int(k,2))); #result of 1100/10\n", "i_j_k=bin(int(i,2)+int(j_k,2)); #result of 101+1100/10\n", "\n", "#Result\n", "print \"result of 10110-1011 is\",a_b\n", "print \"result of 1001+1010 is\",c_d\n", "print \"result of 101*100 is\",e_f\n", "print \"result of 1100/11 is\",g_h\n", "print \"result of 101+1100/10 is\",i_j_k" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }