使用布尔变量时出现 Python 语法错误

时间:2021-04-08 15:54:09

标签: python syntax-error

刚接触开发,有一个菜鸟问题。

我在这个 if 块的第二个语句中收到一个语法错误。 不知道为什么?请帮忙。

if engine_capacity <= 1600:
   rate=.25
if engine_capacity >1600 and =<2000:
   rate=.50
if engine_capacity > 2000:
   rate=.75

1 个答案:

答案 0 :(得分:0)

试试这个:

engine_capacity = 2000
if engine_capacity <= 1600:
    rate = .25
if engine_capacity > 1600 and engine_capacity <= 2000: # <-- Should be <= not =<. You also need to type out the entire and statement, not just <= 2000
    rate = .50
if engine_capacity > 2000:
    rate = .75