Python Forum

Full Version: Invalid syntax on print function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys,

I am trying this code out for an assignment and keep getting "SyntaxError: invalid syntax" on the print function.
def f(x):
    return 2*x*x*x - 11.7*x*x + 17.7 * x - 5

x0 = 3  
xold = 0

def modifiedsecant(x0):
    lamda = 0.01
    i = 0
    
    while (i < 4):
        xold = x0 
        i = i + 1  
        x0 = x0 - ((lamda*x0*f(x0))/(f(x0+(lamda*x0))-f(x0))                
    
    print(x0)
  
modifiedsecant(x0)
Appreciate the help.
Some times a syntax error detected on one line means you did something wrong before that point.

Here line 14 doesn't have balanced parentheses. It was hoping the next line would balance them, but when it found the print function leaving the while loop without balancing, it triggered the error.
(Jul-12-2020, 07:33 PM)bowlofred Wrote: [ -> ]Some times a syntax error detected on one line means you did something wrong before that point.

Here line 14 doesn't have balanced parentheses. It was hoping the next line would balance them, but when it found the print function leaving the while loop without balancing, it triggered the error.

Yep that fixed it, thanks!!