PROGRAMMING LOGIC AND DESIGN - LAB
PRACTICE CODES
1. ARITHMETIC OPERATORS
# Addition
a = 5
b = 3
result = a + b
print("Addition:", result) # Output: 8
# Subtraction
a = 10
b = 6
result1 = a - b
result2 = b - a
print("Subtraction 1:", result1) # Output: 4
print("Subtraction 2:", result2) # Output: -4
# Multiplication
a = 4
b = 7
c = -2
result1 = a * b
result2 = a * b * c
print("Multiplication 1:", result1) # Output: 28
print("Multiplication 2:", result2) # Output: -56
x = 10
y = 3
# Division
result = x / y
print("Division:", result) # Output: 3.3333333333333335
# Floor Division (whole number of Quotient)
result = x // y
print("Floor Division:", result) # Output: 3
# Modulo (remainder number of Quotient)
result = x % y
print("Modulo:", result) # Output: 1
# Exponentiation
a = 2
b = 4
result = a ** b
print("Exponentiation:", result) # Output: 16
2. ASSIGNMENT OPERATORS
# Assignment
x = 5
print("Assignment:", x) # Output: 5
# Addition Assignment
x = 10
x += 3 # Equivalent to x = x + 3
print("Addition Assignment:", x) # Output: 13
# Subtraction Assignment
x = 15
x -= 7 # Equivalent to x = x - 7
print("Subtraction Assignment:", x) # Output: 8
# Multiplication Assignment
x = 4
x *= 5 # Equivalent to x = x * 5
print("Multiplication Assignment:", x) # Output: 20
# Division Assignment
x = 25
x /= 5 # Equivalent to x = x / 5
print("Division Assignment:", x) # Output: 5.0
# Modulo Assignment
x = 17
x %= 5 # Equivalent to x = x % 5
print("Modulo Assignment:", x) # Output: 2
# Exponentiation Assignment
x = 3
x **= 4 # Equivalent to x = x ** 4
print("Exponentiation Assignment:", x) # Output: 81
# Floor Division Assignment
x = 27
x //= 4 # Equivalent to x = x // 4
print("Floor Division Assignment:", x) # Output: 6
3. COMPARISON OPERATORS
# Equal to
a = 5
b = 5
result = a == b
print("Equal to:", result) # Output: True
# Not equal to
a = 7
b = 3
result = a != b
print("Not equal to:", result) # Output: True
# Greater than
a = 10
b = 5
result = a > b
print("Greater than:", result) # Output: True
# Less than
a = 3
b = 8
result = a < b
print("Less than:", result) # Output: True
# Greater than or equal to
a = 7
b = 7
result = a >= b
print("Greater than or equal to:", result) # Output: True
# Less than or equal to
a = 4
b = 6
result = a <= b
print("Less than or equal to:", result) # Output: True
4. LOGICAL OPERATORS
# Logical AND
a = True
b = False
result = a and b
print("Logical AND:", result) # Output: False
# Logical OR
a = True
b = False
result = a or b
print("Logical OR:", result) # Output: True
# Logical NOT
a = True
result = not a
print("Logical NOT:", result) # Output: False
5. UNARY OPERATORS
a = -10
b = 5
print("A = " + str(a))
print("B = " + str(b))
print("\nAAA = ", a)
print("BBB = ", b)