简体   繁体   English

这个语法错误是什么意思。 我写的代码很好。 问题是什么?

[英]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.为什么我会遇到这个问题: SyntaxError: EOL while scaning 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') .由于'*' ('c' '+' 'b')出现 EOL 错误。 The computer believes that this code is trying to run a function, much like print() .计算机认为这段代码正在尝试运行一个函数,很像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:我想您要做的是使函数输出为Forced Order: a*(c+b)=24 。这可以通过两个快速修复来解决:

First, there's a typo.首先,有一个错字。 '=' should use ' not ' on both sides. '='应该在两边都使用' not '

Second, the parenthesis need to be parts of the string.其次,括号需要是字符串的一部分。 The parenthesis in ('c' '+' 'b') are not part of any strings. ('c' '+' 'b')中的括号不是任何字符串的一部分。 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.它们可以像函数的其余部分一样单独转换为字符串,或者,就像字符串"Forced Order:" ,字符串"a*(c+b)"可以作为一个字符串写出,而不是串联一个系列单个字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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