What if…? or elif…? or else?

--Originally published at PYTHON 3

The if help us to check conditions, and we usually use them with inputs.

 

For example…

age = int(input(“enter your age: “ ))

I am making a variable called age which is an int/input.

 

if age >= 18:

(Instructions)

elif age < 18:  

        (Instructions)

else:

       (“Error, what are you typing?”)

 

After typing your age, the code is telling if that number is equal or greater than 18 it will run a set of instructions, any instructions the coder wants.

But if that condition doesn’t complete, we have our elif, which is our plan B (that will also run another set of instructions)

But if any of those statements aren’t true then we can use or else, which is like our plan C/ backup plan (which runs another set of instructions if all of the ones before aren’t true)

9ba2dc39-0aa4-40c5-bfbb-a84af7825364.gif

It’s that easy, yet so beautiful and amazing.

 

Here’s a python code I made using ifs, elifs, and else

Screenshot from 2016-09-05 21-59-02

Screenshot from 2016-09-05 21-59-31

Screenshot from 2016-09-05 21-58-00

I tried like 30 times and never got the right number, that’s bad luck.

Check out the page that helped me learn about ifs?

http://www.ibiblio.org/g2swap/byteofpython/read/if-statement.html