{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter3 - Functions & Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex3.8 Pg 60"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of 4! is :  24\n"
     ]
    }
   ],
   "source": [
    "def recur_factorial(n):\n",
    "    if n == 1:\n",
    "        return n\n",
    "    else:\n",
    "        return n*recur_factorial(n-1)\n",
    "\n",
    "a=4\n",
    "p=recur_factorial(a)\n",
    "print 'the value of 4! is : ',p\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex3.10 Pg 63"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the polynomial(p) is :  2*x**3 - 7*x**2 + 4*x - 15\n",
      "f(a) at a= 5 is :  80\n"
     ]
    }
   ],
   "source": [
    "from sympy import symbols, solve\n",
    "x = symbols('x')\n",
    "p = 2*x**3-7*x**2+4*x-15\n",
    "print 'the polynomial(p) is : ',p\n",
    "# Let x=5\n",
    "x=5\n",
    "p = 2*x**3-7*x**2+4*x-15\n",
    "print \"f(a) at a= 5 is : \",p\n"
   ]
  }
 ],
 "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
}
