Python Forum
Invalid syntax on print function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid syntax on print function
#1
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.
Reply
#2
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.
Reply
#3
(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!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 1,037 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  print(data) is suddenly invalid syntax db042190 6 3,038 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  How to print variables in function? samuelbachorik 3 1,750 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  [Solved] unkown (to me) function def parm "name1:name2" syntax. MvGulik 5 2,101 Nov-11-2022, 11:21 AM
Last Post: MvGulik
  How to print the output of a defined function bshoushtarian 4 2,218 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 3,402 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  SyntaxError: invalid syntax ?? korenron 15 9,637 Jan-25-2022, 11:46 AM
Last Post: korenron
  Invalid syntax with an f-string Mark17 7 14,941 Jan-14-2022, 04:44 PM
Last Post: Mark17
  Why does absence of print command outputs quotes in function? Mark17 2 2,051 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  return vs. print in nested function example Mark17 4 2,660 Jan-04-2022, 06:02 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020