Python Forum
Invalid syntax on print function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Invalid syntax on print function (/thread-28288.html)



Invalid syntax on print function - DoctorSmiles - Jul-12-2020

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.


RE: Invalid syntax on print function - bowlofred - Jul-12-2020

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.


RE: Invalid syntax on print function - DoctorSmiles - Jul-12-2020

(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!!