简体   繁体   中英

what does this syntax error means. I wrote my code good. What is the problem?

why do I get this problem: SyntaxError: EOL while scanning string literal. Can someone please tell me where my fault is.

a = 2
b = 4
c = 8
print ("Forced Order:" 'a', '*' ('c' '+' 'b') '=’ a*(c+b))

The EOL error specifically appears because of '*' ('c' '+' 'b') . The computer believes that this code is trying to run a function, much like print() . The error pops up because a string cannot call a function like this.

What I imagine your trying to do is make the function output is Forced Order: a*(c+b)=24 .That can be solved with two quick fixes:

First, there's a typo. '=' should use ' not ' on both sides.

Second, the parenthesis need to be parts of the string. The parenthesis in ('c' '+' 'b') are not part of any strings. Either they can be individually turned into strings like the rest of the function or, just like with the string "Forced Order:" , the string "a*(c+b)" can be written out as one string instead of concatenating a series of single characters.

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