你为什么在这个IF语句中得到了一个语法错误?

huangapple go评论70阅读模式
英文:

Why am I getting a Syntax error for this IF statement?

问题

> > `x = 18.0  If x < 18.5:
> >     print("Less than 18.5")`

我预期它会打印,但实际上我得到了以下错误
If x < 18.5: ^ SyntaxError: 语法错误

我在Jupyter Notebook中使用Python 3。

a = 33 b = 200 if b > a: print("b is greater than a") 这段代码有效,但上面的代码不有效。

英文:
> > `x=18.0  If x < 18.5:
> >     print("Less than 18.5")`

I'm expecting it to print but instead I get this error
If x < 18.5:
^
SyntaxError: invalid syntax

I'm using Python 3 in Jupyter Notebook.

a = 33
b = 200
if b > a:
print("b is greater than a")
This code works but not the code above.

答案1

得分: 1

The if shouldn't be capitalized in your code.

英文:

The if shouldn't be capitalized in your code.

答案2

得分: 1

你现在是大写的"if",而且你的缩进是错误的,应该看起来像这样:

x = 18.0
if x < 18.5:
    print("小于18.5")
英文:

you are capitalizing if, also your indentation is wrong, it should look something like

x = 18.0
if x &lt; 18.5:
    print(&quot;Less than 18.5&quot;)

huangapple
  • 本文由 发表于 2023年6月8日 11:11:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定