-4

new to development and have a rookie question.

I'm receiving a syntax error in the 2nd statement of this if block. No idea why? Please help.

if engine_capacity <= 1600:
   rate=.25
if engine_capacity >1600 and =<2000:
   rate=.50
if engine_capacity > 2000:
   rate=.75
GCJase
  • 1
  • 4
    Because `=<2000` is not a valid expression; it's just a fragment. Also `=<` is not a valid operator. Perhaps you meant `1600 < engine_capacity <= 2000`. Though `elif` / `else` would be more elegant. – khelwood Apr 08 '21 at 15:55
  • 2
    should be `if engine_capacity > 1600 and engine_capacity <= 2000:` – Krishna Chaurasia Apr 08 '21 at 15:55
  • 2
    Or `if 1600 < engine_capacity <= 2000` for short – Kemp Apr 08 '21 at 15:56
  • or better yet, `elif engine_capacity <= 2000`. – Fred Larson Apr 08 '21 at 15:58
  • Thanks team. I'm definitely trying to be as elegant or accurate as possible. elif we'll try. – GCJase Apr 08 '21 at 16:06
  • So this is my program, I definitely need some expert advice. market_price = float(input('Enter the market price: ')) engine_capacity = float(input('Enter the engine capacity (number only): ')) manufacture_year = float(input('Enter the manufacture year: ')) initial_customs_amount = market_price * rate if engine_capacity <=1600: rate=0.25 elif engine_capacity <=2000: rate=0.50 elif engine_capacity >2000: rate=0.75 depreciation_discount = market_price * ((2021 - manufacture_year) / 100) final_customs_amount = initial_customs_amount - depreciation_discount – GCJase Apr 08 '21 at 16:42

1 Answers1

0

Try this:

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
Dugbug
  • 454
  • 2
  • 11