简体   繁体   中英

python print invalid syntax

print (n+1) ": x1= ",x1,"f(x)= ",fx

I want it to print what the x1 is and the value of the function at x1 (fx), but I get an invalid syntax on the end of the first quotation. Can someone explain to me what my problem is.

这是你想要做的(假设所有都是整数):

print("%d: x1= %d f(x)=%d" % ((n+1),x1,fx))

你在n + 1之后错过了一个逗号

print (n+1), " : x1=",x1,"f(x)=",fx 

The problems are

  1. There should be a comma(,) before the 1st quotation.

    print (n+1), " : x1=",x1,"f(x)=",fx

  2. printing f(x) will print correct value if you have a return statement in the function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM