Python Condition Expressions | Learn With Pirates
Chapter 6: Python Condition Expressions
Conditions in Python
When you login into your social media account's you need to put the correct credential on the portal.
in this case, if your password is not correct they give the statement "please input correct condition".
so these decisions depend on a condition. In python we able to program with conditions.
in this case, if your password is not correct they give the statement "please input correct condition".
so these decisions depend on a condition. In python we able to program with conditions.
if, else and elif in Python
a=8
if (a==7):
print("Great number")
else:
print("Much Great Number")
Output
Much Great Number
Some operators the use in Python
age = int(input("Enter your age: "))
work_Ex = 4
if(age>18 or work_Ex<56):
print("You can work with us")
else:
print("You cannot work with us")
Output
Enter your age: 19
You can work with us
Relation Operators
Relation operators are used to evaluating conditions inside the if statement. some examples of the relational operator are:
Relational Operator
== #equals
>= #Grater than/ equal to
<= #Less then
!= #Not Equals To
logical Operators
In python logical operator operates on conditional statements example:
Logical Operator
and #Use for both are True
or #One are True
not #invert True to flase
elif condition:
What happens when you have three or more condition how you use if statement: that case you can use with elif
a= int(input("enter number: "))
if (a==0):
print("The value of is 0")
elif(a<0):
print("The valuse of number is nagative")
elif(a>0):
print("The Value of number is positive ")
else:
print("error")
Output
enter number: 6
The Value of number is positive
Note
- You can declare elif number of you can.
- last else is execute only if all the if and elif statement fails.
Termination:
If you Like this tutorial please share with your friend and family. I make an amazing tutorial in this blog. If you have any queries and question ask me in the comment section below.
No comments
Post a Comment