Arithmetic, Assignment ,Logical, and Relational Operators in Python
# Assignment 1
# Arithmetic Operators
print("ASSIGNMENT_1")
print("--Arithmetic Operators --")
a=int(input("Enter first number:"))
b=int(input("Enter first number:"))
c=a+b
print("sum:",c) #Add the two number
d=a-b
print("Difference:",d) #Subtract the two number
e=a*b
print("Multiplication:",e) # Multply the two number
f=a/b
print("Division:",f) # Divide the two number
g=a**b
print("Power:",g) # Return the power of number
h=a//b
print("Floor division:",h) # Remove the digit after decimal point for positive number 15/2 = 7 and for negative number it roundoff the result like -15/2 = -8
i=a%b
print("Modulus:",i) # Return the remainder
print("\n")
# Assignment Operator
print("--Assignment Operator--")
m=4
print("Assigning the value 4 to m :",m)
m+=7
print("Increment the value by 7 :",m)
m/=2
print("Divide the value by 2 :",m)
m//=2
print("Floor division by 2 :",m)
m-=1
print("decrement the value by 1 :",m)
m*=5
print("Multiply the value by 5:",m)
m**=2
print("Power by 2 :",m)
m%=2
print("Modulus by 2 :",m)
print("\n")
print("--Logical Operator--")
# Logical Operator
# and
x=6
print("The and operation result is:",x>2 and x<7) # If both the condition is True then it is True
# or
print("The or operation result is:",x>2 or x<5) # If any one condition is True then it is True
#not
print("The not operation result is:",not(x>2 and x<7)) # It return opposite of result. if condition is true then it return false
print("\n")
# Relational operator
print("--Relational operator--")
print("a>b :", a>b)
print("a<b :", a<b)
print("a==b :", a==b)
print("a!=b :", a!=b)
print("a>=b :", a>=b)
print("a<=b :", a<=b)
Comments
Post a Comment