VELAMMAL BODHI CAMPUS- ATTUR WEEK-2(PRACTICE THE OPERATOR SAMPLE CODING USING SOFTWARE)
1. ADDITION OF TWO NUMBERS :
CODING CLUB ACTIVITY FOR HIGH COMPARTMENT
# Python3 program to add two numbers
PYTHON CODING – JULY MONTH
num1 = 15
WEEK-1(OPERATOR ( ADD,SUBTRACT, MULTIPLY, DIVIDE) WITH SAMPLE PROGRAM)
num2 = 12
In Python programming, Operators in general are used to perform operations on values and variables.
These are standard symbols used for logical and arithmetic operations. In this article, we will look into # Adding two nos
different types of Python operators.
sum = num1 + num2
OPERATORS: These are the special symbols. Eg- + , * , /, etc. # printing values
OPERAND: It is the value on which the operator is applied.
print("Sum of", num1, "and", num2 , "is", sum)
Description Syntax
Addition Operator + Addition: adds two operands x+y WORKOUT :
i)WRITE A PROGRAM FOR SUBTRACTION OF TWO NUMBERS
ii) WRITE A PROGRAM FOR MULTIPLICATION OF TWO NUMBERS
Subtraction
– Subtraction: subtracts two operands x–y
Operator iii) WRITE A PROGRAM FOR DIVISION
iv) WRITE A PROGRAM FOR FLOOR DIVISION
v) WRITE A PROGRAM FOR MODULUS OPERATOR
Multiplication
* Multiplication: multiplies two operands x*y
Operator vi) WRITE A PROGRAM FOR EXPONENTIATION OPERATOR
WEEK-3 (OPERATOR:BITWISE,COMPARISON AND SHIFT)
Python bitwise operators are used to perform bitwise calculations on integers.
Division (float): divides the first operand by the
Division Operator / x/y
second
OPERATOR
NAME DESCRIPTION SYNTAX
Floor Division Division (floor): divides the first operand by the Result bit 1, if both operand bits are 1; otherwise
// x // y & Bitwise AND x&y
Operator second results bit 0.
Result bit 1, if any of the operand bit is 1;
| Bitwise OR x|y
otherwise results bit 0.
Modulus: returns the remainder when the first
Modulus Operator % x%y
operand is divided by the second
~ Bitwise NOT inverts individual bits ~x
Exponentiation Power (Exponent): Returns first raised to power Results bit 1,if any of the operand bit is 1 but not
** x ** y ^ Bitwise XOR both, otherwise x^y
Operator second
results bit 0.
The left operand’s value is moved toward right by
Bitwise right
>> the number of bits x>>
shift
specified by the right operand.
The left operand’s value is moved toward left by
Bitwise left
<< the number of bits x<<
shift
specified by the right operand.
WEEK-4 (ILLUSTRATE PROGRAM USING OPERATOR USING PYTHON
The different types of Comparison Operators in Python are as follows: SOFTWARE)
# Comparison operators example
Operator Description Syntax x = 10
y=5
Python Equality a ==
== Equal to: True if both operands are equal # Equal to
Operators b
print(x == y)
# Not equal to
a !=
Inequality Operators != Not equal to: True if operands are not equal
b print(x != y)
# Greater than
Greater than: True if the left operand is greater a> print(x > y)
Greater than Sign >
than the right b
# Less than
print(x < y)
Less than: True if the left operand is less than the a< # Greater than or equal to
Less than Sign <
right b
print(x >= y)
# Less than or equal to
Greater than or Greater than or equal to: True if left operand is a >=
>= print(x <= y)
Equal to Sign greater than or equal to the right b
# Bitwise operators example
Less than or Equal to Less than or equal to: True if left operand is less a <=
<=
Sign than or equal to the right b x = 0b1010 # Binary representation of 10
y = 0b1100 # Binary representation of 12
# Bitwise AND
print(bin(x & y)) # Output: 0b1000
Logical operators are used on conditional statements (either True or False). They perform Logical
AND, Logical OR, and Logical NOT operations. # Bitwise OR
OPERATOR DESCRIPTION SYNTAX Example print(bin(x | y)) # Output: 0b1110
Returns True if both # Bitwise XOR
and the operands are x and y x>7 and x>10 print(bin(x ^ y)) # Output: 0b0110
true
Returns True if # Bitwise NOT
or either of the x or y x<7 or x>15
operands is true print(bin(~x)) # Output: -0b1011 (Note: Inverted bits with a negative sign due to two's complement
representation)
Returns True if the # Left Shift
not not x not(x>7 and x> 10)
operand is false
print(bin(x << 1)) # Output: 0b10100
# Right Shift
print(bin(y >> 1)) # Output: 0b110