Conditionals

--Originally published at Codebuster

Another important thing are conditionals, conditionals are a way to check for something, they evaluate true or false and execute something.

The “if” statement evaluates when a parameter given is true, if it is it will do what your specified.

If can evaluate things like

> (less than)
< (greater than)
>= (less or equal than)
<= (greater or equal than)
== (equals)

The “else” statement is a conditional that only executes if the expression “if” results false.

But there is another conditional that lies between these two, called “elif”, this conditional is used when we want to evaluate if another condition is true, in the same block as the first if function, as such:

if  5>6:
print (“Yes”)

elif 7>6:
print(“Yup”)

else 8>6:
print (“Ok”)

In that code, the result would be “Yup” because the code would run and stop after elif, since the condition was true.

Here is another the example I worked on with Max (go check out his blog, it’s a cool one).

code-max

So here’s what would happen if you did pass

max-yes

Oooor, if you didn’t make it…

max-sucks

thats-all-folks

 

P.d. Here is a great video that talks about conditionals

https://www.youtube.com/watch?v=mQrci1kAwh4