Let's talk about the if-else statement.
In programming, mostly use conditional statement.
you can't think to solve any problem without a conditional statement.
you can see the example of the if-else condition in the picture.
if (it's raining)
then I will take the umbrella
else
not
this is so easy. isn't it?
now I m gonna show you. that how to write a conditional statement in python language. before that, let's look at a flowchart of a conditional statement.
In that flowchart, you can clearly see, if the condition(its rating) is true then he will take an umbrella if the condition is not true then he will not take an umbrella.
Syntax:
if condition:
print('if the statement is true then print me')
else:
print('if that condition was not true then print me')
this is the conditional syntax in python.
remember, you have must input a colon after a condition, and should execute in the next line.
otherwise, you can get an error.
this is the right syntax. there has no error.
">" this is the 'greater than" operator.
this operator has to check if their age is greater than 18 or not.
in a programming language, there have many mathematical operators.
don't worry about this. I am gonna talk about that.
">" --this is "greater than operator".
"<" -- this is "smaller than operator".
"=" -- this assignment operator.
"==" --this is equal to operator.
"%" --this is the modulus operator or reminder.
that's it for today.
The next day I am gonna post about the nested loop.
and thanks for reading this.
happy coding.
Top comments (0)