2.Program using operators in python.
while("true"):
print("1.Arithmetic operator")
print("2.Comparison operator")
print("3.Assignment operator")
print("4.Logical operator")
print("5.Membership operator")
print("6.Identity operator")
print("7.Exit")
ch=int(input("Enter your choice :"))
if(ch==1):
print("Arithmetic operator")
a=int(input("Give the a value :"))
b=int(input("Give the b value :"))
print("\nAddition ")
print("Sum of two value is",a+b)
print("\nSubraction")
print("Subtract a from b is",a-b)
print("\nMultiplication")
print("Multiply of two num is ",a*b)
print("\nDivision")
print("Division of two is ",a/b)
print("\nModulus")
print("Modulus of two is ",b%a)
print("\nPower")
print("Power of two is ",a**b)
print("---------------------------------------------------------------------------------------")
if(ch==2):
print("Comparison operator")
a=int(input("Give the a value :"))
b=int(input("Give the b value :"))
print(" a==b is",a==b)
print(" a!=b is",a!=b)
print(" a<=b is",a<=b)
print(" a>=b is",a>=b)
print(" a<b is",a<b)
print(" a>b is",a>b)
print("-------------------------------------------------------------------------------------------------")
if(ch==3):
print("Assignment operator")
a=int(input("Give the a value :"))
b=int(input("Give the b value :"))
a+=b
print("(a+=b is same as a=a+b) a=",a)
print("a=",a," b=",b)
a-=b
print("(a-=b is same as a=a-b) a=",a)
print("a=",a," b=",b)
a*=b
print("(a*=b is same as a=a*b) a=",a)
print("a=",a," b=",b)
a/=b
print("(a/=b is same as a=a/b) a=",a)
print("a=",a," b=",b)
a%=b
print("(a%=b is same as a=a%b) a\=",a)
print("-------------------------------------------------------------------------------------------------")
if(ch==4):
print("Logical operator")
a=int(input("Give the a value :"))
b=int(input("Give the b value :"))
c=int(input("Give the c value :"))
d=int(input("Give the d value :"))
res=a>b and c>d
print("a>b and c>d is",res)
res=a>b or c>d
print("a>b or c>d is",res)
res=not a==b
print("not a==b is",res)
print("-------------------------------------------------------------------------------------------------")
if(ch==5):
print("Membership operator")
list=[1,2,3,4,5,6,7,8,9,10]
n=int(input("Give the n value :"))
res=n in list
print(n," in list is",res)
res=n not in list
print(n,"not in list is",res)
print("-------------------------------------------------------------------------------------------------")
if(ch==6):
print("Identity operator")
a=int(input("Give the a value :"))
b=int(input("Give the b value :"))
res=a is b
print("a is b :",res)
res=a is not b
print("a is not b :",res)
print("-------------------------------------------------------------------------------------------------")
if(ch==7):
print("program finished")
break
Output
1.Arithmetic operator
2.Comparison operator
3.Assignment operator
4.Logical operator
5.Membership operator
6.Identity operator
7.Exit
Enter your choice :1
Arithmetic operator
Give the a value :10
Give the b value :20
Addition
Sum of two value is 30
Subraction
Subtract a from b is -10
Multiplication
Multiply of two num is 200
Division
Division of two is 0.5
Modulus
Modulus of two is 0
Power
Power of two is 100000000000000000000
---------------------------------------------------------------------------------------
1.Arithmetic operator
2.Comparison operator
3.Assignment operator
4.Logical operator
5.Membership operator
6.Identity operator
7.Exit
Enter your choice :7
program finished