Logical operators
Logical operators are used to combine one condition with another condition and after combining these two, a new condition is create in the form of true or false.
There are three types of logical operator .
1.AND
2.OR
3.NOT
--------------------------------------------------------------------------------------
Here i can the AND operator with example of python.
AND operator when both two condition are true, they show True .
#Syntax with example.
first_pattern=input('Tell me your 1st pattern:')
second_pattern=input('Tell me your 2nd pattern:')
if first_pattern=='zunair' and second_pattern=='kashan':
print('Unlock')
else:
print('try again')
#output:
OR:
OR operator when only one condition is true , they show true.
#Syntax with example.
first_pattern=input('Tell me your 1st pattern:')
second_pattern=input('Tell me your 2nd pattern:')
if first_pattern=='zunair' or second_pattern=='kashan':
print('Unlock')
else:
print('try again')
#output:
NOT operator when any condition is true , they return into false .
#Syntax with example.
first_pattern=input('Tell me your 1st pattern:')
second_pattern=input('Tell me your 2nd pattern:')
if first_pattern=='zunair' and second_pattern=='kashan':
print('Unlock')
elif first_pattern is not 'zunair':
print('your 1st pattern is wrong')
elif second_pattern is not 'kashan':
print('your 2nd pattern is wrong')
else:
print('try again')
#output:
1 Comments
Brilliant
ReplyDelete