if Statements in python 3

if Statements in python 3

·

1 min read

Day 4

if Statements

With If statements, if the condition evaluates to True, the statements are carried out. Otherwise, they aren't carried out.

An if statement looks like this:

Screen Shot 2022-04-04 at 19.59.18.png

One Simple Example:

Screen Shot 2022-04-04 at 20.01.29.png

Output :

Screen Shot 2022-04-04 at 20.02.22.png

Ok, but when is life ever that simple? Sometimes we’ll have to perform more complex checks. But that’s no problem, because if statements can be nested, one inside the other.

This means that the inner if statement is the statement part of the outer one. This is one way to see whether multiple conditions are satisfied.

Screen Shot 2022-04-04 at 20.05.55.png

Screen Shot 2022-04-04 at 20.06.08.png

The if else statement can also be used by extending it by using the elseif statement. The shortform of the elseif statement in python is elif.

Sample code:

Screen Shot 2022-04-04 at 20.11.19.png

Screen Shot 2022-04-04 at 20.11.33.png

NOW! IT'S TIME FOR THE END LESSON QUESTIONS :

What is the output of the program:

x = 50

if x <= 19 :

        print ("The number is less then or equals to 10")

elif x <=49 :

        Print ("The number is less then or equals to 40")

else :

        print ("The number is more than or equals to 50 ")

COMMENT THE ANSWER... ///