Module_2[1]
Module_2[1]
Ex:
x=5
Output:
False
True
False
01-07-2024 Dr. V.Srilakshmi 8
Membership operators
• They are used to test whether a value or variable is found in a
sequence (string, list, tuple, set and dictionary).
• In a dictionary we can only test for presence of key, not the
value.
X: 0000 1010
Y: 0000 1011
X|Y : 0000 1011
result is 11
X: 0000 1010
Y: 0000 1011
X^Y : 0000 0001
result is 1
a = 0011
~a = 1100
01-07-2024 Dr. V.Srilakshmi 12
Bitwise operators
Bitwise Left Shift Operator «
• This operator shifts the bits of the number towards left a
specified number of positions.
X<<n=x*2n
X=10;
X<<2=10x22
=10x4= 40
Ex:
a1 = 3
b1 = 3
print(a1 is b1)
print(a1 is not b1)
• Operators have different levels of precedence, which determine the order in which
they are evaluated.
• When multiple operators are present in an expression, the ones with higher
precedence are evaluated first.
• In the case of operators with the same precedence, their associativity comes into play,
determining the order of evaluation.
In this expression ‘*’ and ‘/’ have the same precedence and their
associativity is Left to Right,
so the expression “100 / 10 * 10” is evaluated as
=(100 / 10) * 10
=10*10
value=100
3. What is the value of 100 + 200 / 10 - 3 * 10
1.Multiplication: 3 * 2 = 6
2.Addition: 4 + 6 = 10
3.Bitwise AND: 10 & 4 = 0 (In binary, 10 is 1010 and 4 is 0100. The result of a bitwise AND is 0 where there
are differing bits.)
4.Bitwise OR: 0 | 6 = 6 (In binary, 0 is 0000 and 6 is 0110. The result of a bitwise OR is 1 where there is at
least one 1.)
So, the final result of the expression is 6.
print(“VIT-AP”)
• output:
print(“name”)
print(“collegename”)
• output:
print(x)
• output:
• write python program to assign multiple objects to multiple variables and display on the screen
a=10
b=45.78
c=”Hello”
print(“a=”,a)
print(“b=”,b)
print(“c=”,c)
• output:
x=[10,20,30]
print(10 in x)
print(60 in x)
print(10 not in x)
print(60 not in x)
output:
import calendar
year = int(input("Enter year: "))
month = int(input("Enter month: "))
cal = calendar.month(year, month)
print(cal)
• Here, the program evaluates the test expression and will execute
statement(s) only if the text expression is True.
• If the text expression is False, the statement(s) is not executed.
• In Python, the body of the if statement is indicated by the
indentation.
• Body starts with an indentation and the first unindented line marks
the end.
• if...elif...else Statement allows you to execute different blocks of code based on specified
conditions.
Score Grade
>=0.9 A
>=0.8 B
>=0.7 C
>=0.6 D
<0.6 F
01-07-2024 Dr. V.Srilakshmi 36
• Write a program to calculate and print the amount
of money to be paid by a customer based on the
details given below in the table. Customer has to
pay 9% GST on the remaining/discounted price(i.e.
MRP- discount) also.(use MRP to take input by the
user during run-time and “Amount” to print the
output) MRP Discount
Upto Rs.2000 5%
Rs.2000 to Rs. 5000 10%
Rs.5000 to Rs. 10000 15%
Program:
signal=input ("enter signal")
if(signal=="red"):
print("STOP")
elif(signal=="orange"):
print ("Be slow")
elif(signal=="green"):
print ("to go")
else:
print("error")