Session 3.ipynb
Session 3.ipynb
ipynb - Colaboratory
Comparison Operators
= equal to
== to check whether LHS = RHS
!= not equal to
> greater than
< Less than
>= greater than equal to
<= less than equal to
*Comparison Operator *
a=5
b=4
s= a==b
print(s)
#print(a==b)
False
output True
False
True
True
False
1. WAP to take 2 input from the user ad check whther they are equal or different
https://colab.research.google.com/drive/1RnIqJzojDBzOyNVG4XMalzF1nTOfrxam#printMode=true 1/4
10/20/23, 10:56 AM Session 3.ipynb - Colaboratory
3. WAP to take 2 string as input znd check whether they are equal or different
if 25<=x<=75:
print("Entered number is in between 25 to 75")
else:
print("Entered number is out of range")
x=input("Enter a vowel=")
if x in 'aeiou':
print("Entered character is a vowel")
else:
print("Entered character is not a vowel")
Enter a vowel=a
Entered character is a vowel
*Assignment Operator *
x = 5
x += 3 # x is now 8
print(x)
x -= 2 # x is now 6
print(x)
x *= 4 # x is now 24
print(x)
x /= 3 # x is now 8.0
print(x)
x %= 5 # x is now 3.0
print(x)
8
6
24
8.0
3.0
https://colab.research.google.com/drive/1RnIqJzojDBzOyNVG4XMalzF1nTOfrxam#printMode=true 2/4
10/20/23, 10:56 AM Session 3.ipynb - Colaboratory
LOGICAL OPERATOR
x=True
y=False
if x and y:
print("Both x and y are true")
else:
print("At least one of x and y is false")
x=3
y=9
if x<5 and y>5:
print("Both conditions are true")
else:
print("Any one of the conditions is not true")
x=3
y=9
if x<5 or y==5:
print("Any one of the condition is true")
else:
print("Both conditions are false")
#not operator
x= True
if not x:
print("x is false")
else:
print("x is true")
x is true
https://colab.research.google.com/drive/1RnIqJzojDBzOyNVG4XMalzF1nTOfrxam#printMode=true 3/4
10/20/23, 10:56 AM Session 3.ipynb - Colaboratory
username="user123"
password="secure@123"
username=input("Enter the user name:")
password=input("Enter the user password:")
if username=="user123" and password=="secure@123":
print("Access Granted. Welcome User123!")
else:
print("Access Denied. Please check your name and password.")
age=16
has_permission=True
is_resident=True
if age>=18 or (has_permission and is_resident):
print("You are eligible to participate in the contest")
else:
print("You are not eligible for the contest")
Membership operator
list1 = [1, 2, 3, 4, 5]
is_present = 3 in list1 # True
print(is_present)
is_not_present = 6 not in list1 #True
print(is_not_present)
True
True
Temporary Operator
age = 20
can_vote = "Yes" if age >= 18 else "No"
print(can_vote)
Yes
https://colab.research.google.com/drive/1RnIqJzojDBzOyNVG4XMalzF1nTOfrxam#printMode=true 4/4