I am tasked with writing a program to do the bisection method to solve for the sqrt(2) with 6 iterations of the bisection method. Here is my code. I cannot get it to print the values along the way or in the end and I am not sure why.
import math
>>> def f(x):
return (x**2)-2
>>> def bisect (a,b,n):
while n < 6:
c=(a+b)/2
if f(c) == 0:
print [('Root is: ', c)]
elif f(a)*f(b) > 0:
b=c
n=(n+1)
print [('n: ',n,' c: ',c)]
else:
a=c
n=(n+1)
print [('n: ',n,' c: ',c)]
>>> print bisect (0,1,0)
SyntaxError: invalid syntax
>>> print bisect (0,1,0):
SyntaxError: invalid syntax
>>>