##Operators & Binary Number System on Python##
Arithmetic Operators
#Addition
print(6+7)
# substraction
print(5-2)
# Multipication
print(10*2)
#Division
print(6/4)
#Modulus
print(6%4)
# Exponenttion
print(4**2)
#Florr divison
print(6//4)
#Comarison Operator/Relational
#Less then
print(6<7)
# Greater Than
print(6>7)
#Equal
print(6==7)
#Not Equal
print(6!=7)
#Less then equal
print(6<=7)
#Greater then equal
print(6>=7)
#Logical Operatos#
# and
# a = True
# b = False
a = (6==7)
b = (9>6)
print("AND operation",a and b)
# or
print("OR operation",a or b)
# not
print("not operation",not a)
print("not operation",not b)
##Bitwise Operators##
a = 4 #100
b =6 #110
# Bitwise and operator
print(a&b) #100
# bitwise or operator
print(a | b)
# bitwise not operator
print(~2)
# bitwise xor operator
print(a^b)
# shift operator:
# bitwise right shift
print(a>>1)
# bitwise left shift
print(b<<1)
#Assignment Operator
a = 6
a += 2
print(a)
a-=2
print(a)
a *=2
print(a)
a /=2
print(a)
a //= 2
print(a)
a **= 2
print(a)
# Identitiy Operators
a = 7
b = a
c =8
# is
print(a is b)
print(a is c)
# is not
print(a is not c)
print(b is not a)
##Membership Operators
lst = [1,2,3,4,5]
# in
print(1 in lst)
# not in
print(1 not in lst)
#Assositivity
print(6*2+3)
print(6/2/3)
print(2**3**2)
# Question (Set Bits)
def countBts(n):
count = 0
while(n!=0):
if(n&1 == 1):
count+=1
n = n>>1
return count
n = int(input("Enter a Number : "))
print(countBts(n))
0 Comments