Page 246 - CTS - CSA TP - Volume 2
P. 246
COMPUTER SOFTWARE APPLICATION - CITS
TASK 2: Assignment Operators
Code:
# Assignment Operators
x = 5
y = 3
x += y
print(f”x after addition: {x}”)
y *= 2
print(f”y after multiplication: {y}”)
Output:
Explanation:
• Addition Assignment (+=): Adds the value of y to the current value of x and assigns the result back to x. In this
case, x becomes 8 (original x value of 5 plus y value of 3).
• Multiplication Assignment (*=): Multiplies the value of y by 2 and assigns the result back to y. In this case, y
becomes 6 (original y value of 3 multiplied by 2).
• These assignment operators provide a concise way to update the values of variables based on their current
values. The results after each assignment operation are then printed for verification.
TASK 3 : Comparison Operators
Code:
# Comparison Operators
x = 10
y = 20
equals = x == y # Equal to
not_equals = x !=y # Not equal to
greater_than = x >y # Greater than
less_than = x <y # Less than
greater_equal = x >= y # Greater than or equal to
231
CITS : IT & ITES - Computer Software Application - Exercise 123