If Else & Elif conditions
If Else
These are the fictions which work or respond upon to the given statements, it is the general work upon to the if or else.
in "if else" lader, the program starts checking the statements one by one, whereas it mays all statements are ture or false.
code👇
var1 = 6
var2 = 56
print("This statement for user to input the number:")
var3 = int(input())
if var3>var2:
print("Greater")
if var3==var2:
print("Equal")
else:
print("Lesser")
This statement for user to input the number:
12
Lesser
Dissection of the used functions:
"var3" is a variable, where we typecast the variable into the integer, by user input.
":" this sign is always use with if else functions, the meaning of this sign the program is entered into the conditional statements.
"==" In python double equals to means "equals" for the same numbers.
Elif
In python, "Elif "is also a conditional statement whereas, the "Elif" means the "else-if".
in "Eli" lader, the program starts checking the statements one by one, whereas it mays ture then the sequence get broke and execute out of the all statements.
code👇
var1 = 6
var2 = 56
print("This statement for user to input the number:")
var3 = int(input())
if var3>var2:
print("Greater")
elif var3==var2:
print("Equal")
else:
print("Lesser")
This statement for user to input the number:
56
Equal
check true or False into the list by conditional statements
code👇
list1 = [5, 6, 7, 8]
if 5 in list1:
print("Yes, it is here")
if 15 not in list1:
print("NO, it's not here")
Yes, it is here
NO, it's not here
Comments
Post a Comment