Chapter3 - Functions & Algorithms

Ex3.8 Pg 60

In [2]:
def recur_factorial(n):
    if n == 1:
        return n
    else:
        return n*recur_factorial(n-1)

a=4
p=recur_factorial(a)
print 'the value of 4! is : ',p
the value of 4! is :  24

Ex3.10 Pg 63

In [6]:
from sympy import symbols, solve
x = symbols('x')
p = 2*x**3-7*x**2+4*x-15
print 'the polynomial(p) is : ',p
# Let x=5
x=5
p = 2*x**3-7*x**2+4*x-15
print "f(a) at a= 5 is : ",p
the polynomial(p) is :  2*x**3 - 7*x**2 + 4*x - 15
f(a) at a= 5 is :  80