Professional Documents
Culture Documents
7. Take two number and check whether the sum is greater than, less than or
equal to 20
1/5
Department: Information Technology
Course Name: Python
2. a=2
b=4
c=7
d=9
print(d>b and c!=a)
print(b>d and a<d)
print(d<b or c!=a)
print(b>d or a<d)
print(not a>=d)
print(a >= 2 and (a/b) > 2)
3. student_one="Omar"
student_two="omar"
student_three="Omar"
print(student_one!= student_two)
print(student_two == student_three)
2/5
Department: Information Technology
Course Name: Python
3/5
Department: Information Technology
Course Name: Python
Summry
1. Comparison Operators
Operator Meaning
> Greater than
< Less than
== Equal to
!= Not equal to
>= Greater than or equal to
<= Less than or equal to
2. Logical operators
Operator Meaning
and True if both the operands are true
or True if either of the operands is true
True if operand is false (complements
not
the operand)
x y Returns
True True True
True and False False
False True False
False False False
x y Returns
True True True
True or False True
False True True
False False False
x Returns
not True False
False True
4/5
3. Syntax of if...else Statement
if test condition:
Body of if
else:
Body of else
The if..else statement evaluates the test condition and will execute body of
if only when test condition is True.
If the condition is False, body of else is executed.
The elif is short for else if. It allows us to check for multiple expressions.
If the test condition for if is False, it checks the test condition of the next
elif block and so on.
If all the test conditions are False, body of else is executed.
The if block can have only one else block. But it can have multiple elif
blocks.
5/5