Class - 12 CBSE Computer Science Important Output Questions 2025
Predict the output of the following code snippet ?
Numbers = [9, 18, 27, 36]
for Num in Numbers :
for N in range(1, Num % 8) :
print(N, "#", end=" ")
print( )
Python
Python List Manipulation
12 Likes
Answer
1 #
1 # 2 #
1 # 2 # 3 #
Working
Numbers
is a list containing the numbers 9, 18, 27, and 36.- The outer for loop iterates over each element in the list
Numbers
. - The inner loop iterates over the range from 1 to the remainder of Num divided by 8. For example, if Num is 9, the range will be from 1 to 1 (9 % 8 = 1). If Num is 18, the range will be from 1 to 2 (18 % 8 = 2), and so on. Then it prints the value of N, followed by a "#", and ensures that the output is printed on the same line by setting end=" ".
- After both loops, it prints an empty line, effectively adding a newline character to the output.
Answered By
7 Likes