Elif problem stil not sure how to use


#1



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.


#2

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 ?

Well,
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")

else:
 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.


#3

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


#4

Anyway the elif- syntax in python works like this:

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

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

 else:
      print "Something is wrong with a or b."

#5

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