--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)
It’s that easy, yet so beautiful and amazing.
Here’s a python code I made using ifs, elifs, and else
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