Page 489 - ComputerScience_Class_11
P. 489
D. Higher Order Thinking Skills (HOTS)
1. The following code is intended to check if a year is a leap year:
year = 1900
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
However, the programmer mistakenly removes the or in the condition and uses year % 100 == 0. What will be the result for the
year 1900?
2. A program calculates the sum of two numbers, a and b, using the += assignment operator:
a = 10
b = 5
a += b
If the programmer mistakenly uses the -= operator instead, what would the output be after the operation?
E. Case study-based questions.
In Python, bitwise operators are used to perform operations on individual bits of integer numbers. These operators first convert the
numbers into their binary (0 and 1) form and then perform the required operation bit by bit. Bitwise operators are essential for low-
level programming, data manipulation and situations where direct control over bits is required. For example, the & operator (Bitwise
AND) returns 1 in each bit position if both corresponding bits are 1, while the | operator (Bitwise OR) returns 1 in each bit position if
at least one of the corresponding bits is 1. Similarly, the ^ operator (Bitwise XOR) returns 1 in each bit position if the corresponding
bits are different and the ~ operator (Bitwise NOT) inverts the value of all bits. Bitwise shift operators (<< for left shift and >> for right
shift) allow you to shift the bits of an integer to the left or right, respectively, by a specified number of positions.
Based on the given case, answer the following questions:
1. Given the numbers a = 12 and b = 5, write the Python code to perform the following bitwise operations and explain the result:
a. Bitwise AND (&)
b. Bitwise OR (|)
2. If x = 4 and y = 3, what will be the result of the Bitwise XOR (^) operation between x and y? Show the calculation step by step in
binary form.
3. What happens when the Bitwise NOT (~) operator is applied to the integer 5? Explain the result using binary representation.
4. Given num = 5, what would be the result of shifting the bits of num two positions to the left (<< 2) and two positions to the right
(>> 2)? Provide the calculations in binary form and show the final results.
F. Write the Python program for the following:
1. Write a Python program that calculates the remainder when one number is divided by another using the modulus operator.
2. Write a Python program that checks if a given number is even or odd using the modulus operator.
3. Write a Python program that shifts the bits of an integer to the left using the left shift operator.
G. Find the output of the following programs:
1. a = 15
b = 4
c = a // b
d = a % b
print("Floor Division:", c)
print("Modulus:", d)
2. x = 8
y = 3
z = x ** y
print("Exponentiation Result:", z)
3. x = 7
y = 4
z = (x > y) and (y < x)
print("Logical Operation Result:", z)
Operators and Expressions 487

