Elif problem stil not sure how to use


Good day everyone. I dont quite understand the elif statement. What does it mean by if the original is false, then it will use the elif. Help???

Replace this line with your code.


It is not that hard and I will show you now.

When you want to check something in your program and you are using if, elif, else statements.
You may ask why ?

for example, you are doing the assignment that needs to check temperature outside so you can tell if it is warm, medium or maybe cold outside, or even too cold to go out.

So you would do:

temperature = "some random temperature in Celsius" # this is just example with words 

if temperature >= 30:
  print("weather is a bit hot")

elif temperature <= 30:
  print("weather is getting better")

elif temperature <= 15:
  print("It is getting a bit chilly outside")

elif temperature <= 0:
  print("I'm staying at home today")

 print("I'm staying in bed all day")

So you can see how elif is used to check many other temperature values and to output different strings according to temperature change. You can use as many elif as you want in your code even though it is not the best practice for bigger codes but don't bother with now.


@dayfiri You are writing Javascript. The thread is about Python


Anyway the elif- syntax in python works like this:

if a = b:
      print "a = b!"

 elif a != b:
      print "a != b!"

      print "Something is wrong with a or b."


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.