{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#7: Ratio and Proportion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.1, Page number 7.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "result is 1.2\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=0.75;\n",
    "b=5;\n",
    "c=8;\n",
    "\n",
    "#Calculation\n",
    "x=a*c/b;\n",
    "\n",
    "#Result\n",
    "print \"result is\",x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.2, Page number 7.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mean proportion is 0.08\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=0.32;\n",
    "b=0.02;\n",
    "\n",
    "#Calculation\n",
    "x2=a*b;\n",
    "x=math.sqrt(a*b);    #mean proportion\n",
    "\n",
    "#Result\n",
    "print \"mean proportion is\",x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.3, Page number 7.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "third proportional is 36.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=16;\n",
    "b=24;\n",
    "\n",
    "#Calculation\n",
    "x=(b**2)/a;     #third proportional\n",
    "\n",
    "#Result\n",
    "print \"third proportional is\",x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.4, Page number 7.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "third proportional is 1.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=16;\n",
    "b=4;\n",
    "\n",
    "#Calculation\n",
    "x=(b**2)/a;     #third proportional\n",
    "\n",
    "#Result\n",
    "print \"third proportional is\",x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.5, Page number 7.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "part is 3/4\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "from fractions import Fraction\n",
    "\n",
    "#Variable declaration\n",
    "a=3/48;\n",
    "b=1/12;\n",
    "\n",
    "#Calculation\n",
    "p=a/b;      #part\n",
    "\n",
    "#Result\n",
    "print \"part is\",Fraction(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.6, Page number 7.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "part is 7/8\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "from fractions import Fraction\n",
    "\n",
    "#Variable declaration\n",
    "a=7;\n",
    "b=8;\n",
    "\n",
    "#Calculation\n",
    "p=a/b;      #part\n",
    "\n",
    "#Result\n",
    "print \"part is\",Fraction(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.7, Page number 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of girls is 360.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=4/3;     #ratio of number of boys and girls\n",
    "b=480;    #number of boys\n",
    "\n",
    "#Calculation\n",
    "x=b/a;    #number of girls\n",
    "\n",
    "#Result\n",
    "print \"number of girls is\",x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.8, Page number 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "first part is 32.0 Rs\n",
      "second part is 40.0 Rs\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=4;     #first ratio term\n",
    "b=5;     #second ratio term\n",
    "c=72;    #total amount(Rs)\n",
    "\n",
    "#Calculation\n",
    "fp=a*c/(a+b);   #first part(Rs)\n",
    "sp=b*c/(a+b);   #second part(Rs)\n",
    "\n",
    "#Result\n",
    "print \"first part is\",fp,\"Rs\"\n",
    "print \"second part is\",sp,\"Rs\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.9, Page number 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of girls is 250.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=2;     #first ratio term\n",
    "b=5;     #second ratio term\n",
    "c=350;   #number of students\n",
    "\n",
    "#Calculation\n",
    "x=b*c/(a+b);   #number of girls\n",
    "\n",
    "#Result\n",
    "print \"number of girls is\",x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.10, Page number 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the numbers are 30.0 and 70.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=3;   #first ratio term\n",
    "b=7;   #second ratio term\n",
    "lcm=210;   #lcm of two numbers\n",
    "\n",
    "#Calculation\n",
    "x=lcm/(a*b);   #factor\n",
    "n1=a*x;   #first number\n",
    "n2=b*x;   #second number\n",
    "\n",
    "#Result\n",
    "print \"the numbers are\",n1,\"and\",n2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.11, Page number 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "consequent is 77.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=3;   #first ratio term\n",
    "b=7;   #second ratio term\n",
    "c=33;   #antecedent\n",
    "\n",
    "#Calculation\n",
    "x=b*c/a;   #consequent\n",
    "\n",
    "#Result\n",
    "print \"consequent is\",x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.12, Page number 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the numbers are 12.0 and 20.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "aold=3;   #first ratio term\n",
    "bold=5;   #second ratio term\n",
    "c=4;   #increment\n",
    "anew=2;   #first term of new ratio\n",
    "bnew=3;   #second term of new ratio\n",
    "\n",
    "#Calculation\n",
    "Nr=(aold*c)-(anew*c);\n",
    "Dr=(bold*anew)-(aold*bnew);\n",
    "x=Nr/Dr;     #factor\n",
    "n1=x*aold;\n",
    "n2=x*bold;  \n",
    "\n",
    "#Result\n",
    "print \"the numbers are\",n1,\"and\",n2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.13, Page number 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the numbers are 24.0 and 26.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "aold=12;   #first ratio term\n",
    "bold=13;   #second ratio term\n",
    "c=20;   #decrement\n",
    "anew=2;   #first term of new ratio\n",
    "bnew=3;   #second term of new ratio\n",
    "\n",
    "#Calculation\n",
    "Nr=(bnew*c)-(anew*c);\n",
    "Dr=(bnew*aold)-(anew*bold);\n",
    "x=Nr/Dr;     #factor\n",
    "n1=x*aold;\n",
    "n2=x*bold;  \n",
    "\n",
    "#Result\n",
    "print \"the numbers are\",n1,\"and\",n2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.14, Page number 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "decrement is 0.33\n",
      "answer given in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "aold=3;   #first ratio term\n",
    "bold=7;   #second ratio term\n",
    "anew=2;   #first term of new ratio\n",
    "bnew=5;   #second term of new ratio\n",
    "\n",
    "#Calculation\n",
    "Nr=(aold*bnew)-(anew*bold);\n",
    "Dr=bnew-anew;\n",
    "x=Nr/Dr;    #decrement\n",
    "\n",
    "#Result\n",
    "print \"decrement is\",round(x,2)\n",
    "print \"answer given in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.15, Page number 7.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of people originally present is 12.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "aold=1;   #first ratio term\n",
    "bold=2;   #second ratio term\n",
    "anew=1;   #first term of new ratio\n",
    "bnew=3;   #second term of new ratio\n",
    "g=2;   #number of gents left\n",
    "l=2;   #number of ladies left\n",
    "\n",
    "#Calculation\n",
    "Nr=(g*bnew)-(anew*l);\n",
    "Dr=bnew-(anew*l);\n",
    "x=Nr/Dr;    #factor\n",
    "n=x*(aold+bold);     #number of people originally present\n",
    "\n",
    "#Result\n",
    "print \"number of people originally present is\",n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.16, Page number 7.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of each type of coin is 20.0 coins\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "c1=1;     #coin value 1 rupee\n",
    "c2=0.5;   #coin value 50 paise\n",
    "c3=0.25;  #coin value 25 paise\n",
    "t=35;     #total amount(Rs)\n",
    "\n",
    "#Calculation\n",
    "n=t/(c1+c2+c3);     #number of each type of coin(coins)\n",
    "\n",
    "#Result\n",
    "print \"number of each type of coin is\",n,\"coins\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.17, Page number 7.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fraction of same ratio is 0.183673469388\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=3/7;\n",
    "b=1/5;\n",
    "c=7/15;\n",
    "\n",
    "#Calculation\n",
    "x=a*b/c;      #fraction of same ratio\n",
    "\n",
    "#Result\n",
    "print \"fraction of same ratio is\",x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.18, Page number 7.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "present age of C is 42.0 years\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "s=90;    #sum of ages of A, B, C(years)\n",
    "n=6;     #number of years ago\n",
    "a=1;     #ratio term for age of A\n",
    "b=2;     #ratio term for age of B\n",
    "c=3;     #ratio term for age of C\n",
    "\n",
    "#Calculation\n",
    "age=s-(n*c);    #sum of ages of A, B, C 6 years ago(years)\n",
    "C=c*age/(a+b+c);    #age of C 6 years ago(years)\n",
    "Cp=C+a+b+c;         #present age of C(years)\n",
    "\n",
    "#Result\n",
    "print \"present age of C is\",Cp,\"years\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.19, Page number 7.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "second number is 12.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "s=532;     #sum of squares of 3 numbers\n",
    "a=3;      #first term of ratio\n",
    "b=2;      #second term of ratio\n",
    "\n",
    "#Calculation\n",
    "n1=a*a;   #first number\n",
    "n2=a*b;   #second number\n",
    "n3=b*b;   #third number\n",
    "x2=s/((n1**2)+(n2**2)+(n3**2));\n",
    "x=math.sqrt(x2);     #factor\n",
    "N2=n2*x;     #second number\n",
    "\n",
    "#Result\n",
    "print \"second number is\",N2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.20, Page number 7.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weight of wire is 188.0 kg\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "l1=60;     #length of wire(m)\n",
    "w1=80;     #weight of wire(kg)\n",
    "l2=141;    #length of another wire(m)\n",
    "\n",
    "#Calculation\n",
    "x=w1*l2/l1;    #weight of wire(kg)\n",
    "\n",
    "#Result\n",
    "print \"weight of wire is\",x,\"kg\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.21, Page number 7.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "value of a/bc : b/ca is 4\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "bc=1;    #first term of ratio\n",
    "ac=2;    #second term of ratio\n",
    "ab=3;    #third term of ratio\n",
    "\n",
    "#Calculation\n",
    "#abyb=ac/bc\n",
    "a=ac;\n",
    "b=bc;\n",
    "result=(a**2)/(b**2);     #value of a/bc : b/ca\n",
    "\n",
    "#Result\n",
    "print \"value of a/bc : b/ca is\",int(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.23, Page number 7.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of 1 rupee coins is 5.0\n",
      "number of 50 paise coins is 15.0\n",
      "number of 25 paise coins is 25.0\n",
      "number of 10 paise coins is 35.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "v1=1;     #one rupee coin\n",
    "v2=1/2;   #50 paise coin\n",
    "v3=1/4;   #25 paise coin\n",
    "v4=1/10;   #10 paise coin\n",
    "n1=1;   #number of 1 rupee coins\n",
    "n2=3;   #number of 50 paise coins\n",
    "n3=5;   #number of 25 paise coins\n",
    "n4=7;   #number of 10 paise coins\n",
    "s=22.25;    #total amount(Rs)\n",
    "\n",
    "#Calculation\n",
    "a=(v1*n1)+(v2*n2)+(v3*n3)+(v4*n4);\n",
    "x=s/a;     #factor\n",
    "N1=x*n1;   #number of 1 rupee coins\n",
    "N2=x*n2;   #number of 50 paise coins\n",
    "N3=x*n3;   #number of 25 paise coins\n",
    "N4=x*n4;   #number of 10 paise coins\n",
    "\n",
    "#Result\n",
    "print \"number of 1 rupee coins is\",N1\n",
    "print \"number of 50 paise coins is\",N2\n",
    "print \"number of 25 paise coins is\",N3\n",
    "print \"number of 10 paise coins is\",N4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.24, Page number 7.7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the person should have atleast 57.0 pens\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "from fractions import gcd\n",
    "\n",
    "#Variable declaration\n",
    "a=1/3;\n",
    "b=1/4;\n",
    "c=1/5;\n",
    "d=1/6;\n",
    "\n",
    "#Calculation\n",
    "l1=(1/a)*(1/b)/gcd(1/a,1/b);\n",
    "l2=(1/c)*(1/d)/gcd(1/c,1/d);\n",
    "l=l1*l2/gcd(l1,l2);           #lcm of 3,4,5,6\n",
    "A=a*l;\n",
    "B=b*l;\n",
    "C=c*l;\n",
    "D=d*l;\n",
    "p=A+B+C+D;\n",
    "\n",
    "#Result\n",
    "print \"the person should have atleast\",p,\"pens\""
   ]
  }
 ],
 "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
}