Prasnya
Prasnya
Prasnya
Continue with Google
Prasnya
Continue with Google
Week 7 Programming in Python Questions | Prasnya
Programming in Python > Week 7
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
14Q
01
You have a list of lists. You want to compute the sum of all even numbers greater than 3. Consider the two code snippets below, with the condition left blank. Which conditions, when filled in the blanks in both snippets, will give the correct result? Snippet 1 ``` s = 0 for row in data: for val in row: ____: s += val print(s) ``` Snippet 2 ``` s = 0 i = 0 while i < len(data): j = 0 while ____: if data[i][j] % 2 == 0 and data[i][j] > 3: s += data[i][j] j += 1 i += 1 print(s) ```
Single correct
MEDIUM
4 marks
26 October 2025
02
What is the value of `out1` after executing the code?
Comprehension
MEDIUM
4 marks
26 October 2025
03
What is the value of `out2` after executing the code?
Comprehension
MEDIUM
4 marks
26 October 2025
04
What is the value of `output` after executing the given code snippet?
Comprehension
EASY
4 marks
13 July 2025
05
In the given code, if we change the condition to `if element % 2 == 0` at line 7, then what is the value of `output` after executing it?
Comprehension
EASY
3 marks
13 July 2025
06
What is the first line of the output?
Comprehension
EASY
3 marks
07 July 2024
07
What is the second line of the output?
Comprehension
EASY
3 marks
07 July 2024
08
What is the output of the following snippet of code? ``` P = [[1, 2], [4, 3]] Q = [[4, 1], [9, 3]] R = [] for i in range(2): row = [] for j in range(2): if P[i][j] - Q[i][j] > 0: row.append(1) elif P[i][j] == Q[i][j]: row.append(0) else: row.append(-1) R.append(row) print(R) ```
Single correct
MEDIUM
4 marks
29 October 2023
09
What is the output of the following snippet of code? ``` p = 1 M = [[1, 3, 4], [2, -1, 3], [-2, 1, 2]] m = len(M) n = len(M[0]) for i in range(m): for j in range(n): p = p * M[i][j] print(p) ```
Numerical
MEDIUM
4 marks
29 October 2023
10
Select all matrices, represented as lists of lists `M`, for which the above snippet of code prints `True` to the console. ``` # Look at the options for the value of M n = len(M) flag = True for i in range(n): for j in range(n): if (i != j) and (M[i][j] != 0): flag = False break elif (i == j) and (M[i][j] != 1): flag = False break if flag == False: break print(flag) ```
Multiple correct
MEDIUM
4 marks
16 July 2023
11
Select all matrices `M` for which the following code prints `True` to the console. ``` n = len(M) flag = True for i in range(n): for j in range(n): if (i != j) and (M[i][j] + M[j][i] != 0): flag = False print(flag) ```
Multiple correct
MEDIUM
4 marks
16 October 2022
12
NOTE: Enter your answer to the nearest integer. `R` is a zero-matrix, all entries are zeros, of size
3
×
3
3 \times 3
3
×
3
. Let ``` P = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] Q = [[1, 1, -1], [1, 1, -1], [1, 1, -1]] R = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] ``` What is the output of the following snippet of code? ``` val = 0 for i in range(3): for j in range(3): R[i][j] = P[i][j] * Q[i][j] val = val + R[i][j] print(val) ```
Numerical
MEDIUM
4 marks
16 October 2022
13
Select all matrices `M` for which the following code prints `True` to the console. ``` # Look at the options for the value of M n = len(M) flag = True for i in range(n): for j in range(n): if (i != j) and (M[i][j] != M[j][i]): flag = False print(flag) ```
Multiple correct
MEDIUM
4 marks
05 June 2022
14
`M` is a matrix, represented as a list of lists, that has already been defined. The dimension of `M` is
m
i
m
e
s
n
m imes n
mim
es
n
. Assume that both
m
m
m
and
n
n
n
are greater than or equal to
2
2
2
and all elements of `M` are integers. Select all correct options about the code given below. ``` # M is a matrix (list of lists) that has already been defined n = len(M[0]) flag = True for i in range(n): if M[0][i] - M[-1][i] != 1: flag = False print(flag) ```
Multiple correct
MEDIUM
4 marks
05 June 2022
Showing 14 questions.
Programming in Python > Week 7
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
14Q
01
You have a list of lists. You want to compute the sum of all even numbers greater than 3. Consider the two code snippets below, with the condition left blank. Which conditions, when filled in the blanks in both snippets, will give the correct result? Snippet 1 ``` s = 0 for row in data: for val in row: ____: s += val print(s) ``` Snippet 2 ``` s = 0 i = 0 while i < len(data): j = 0 while ____: if data[i][j] % 2 == 0 and data[i][j] > 3: s += data[i][j] j += 1 i += 1 print(s) ```
Single correct
MEDIUM
4 marks
26 October 2025
02
What is the value of `out1` after executing the code?
Comprehension
MEDIUM
4 marks
26 October 2025
03
What is the value of `out2` after executing the code?
Comprehension
MEDIUM
4 marks
26 October 2025
04
What is the value of `output` after executing the given code snippet?
Comprehension
EASY
4 marks
13 July 2025
05
In the given code, if we change the condition to `if element % 2 == 0` at line 7, then what is the value of `output` after executing it?
Comprehension
EASY
3 marks
13 July 2025
06
What is the first line of the output?
Comprehension
EASY
3 marks
07 July 2024
07
What is the second line of the output?
Comprehension
EASY
3 marks
07 July 2024
08
What is the output of the following snippet of code? ``` P = [[1, 2], [4, 3]] Q = [[4, 1], [9, 3]] R = [] for i in range(2): row = [] for j in range(2): if P[i][j] - Q[i][j] > 0: row.append(1) elif P[i][j] == Q[i][j]: row.append(0) else: row.append(-1) R.append(row) print(R) ```
Single correct
MEDIUM
4 marks
29 October 2023
09
What is the output of the following snippet of code? ``` p = 1 M = [[1, 3, 4], [2, -1, 3], [-2, 1, 2]] m = len(M) n = len(M[0]) for i in range(m): for j in range(n): p = p * M[i][j] print(p) ```
Numerical
MEDIUM
4 marks
29 October 2023
10
Select all matrices, represented as lists of lists `M`, for which the above snippet of code prints `True` to the console. ``` # Look at the options for the value of M n = len(M) flag = True for i in range(n): for j in range(n): if (i != j) and (M[i][j] != 0): flag = False break elif (i == j) and (M[i][j] != 1): flag = False break if flag == False: break print(flag) ```
Multiple correct
MEDIUM
4 marks
16 July 2023
11
Select all matrices `M` for which the following code prints `True` to the console. ``` n = len(M) flag = True for i in range(n): for j in range(n): if (i != j) and (M[i][j] + M[j][i] != 0): flag = False print(flag) ```
Multiple correct
MEDIUM
4 marks
16 October 2022
12
NOTE: Enter your answer to the nearest integer. `R` is a zero-matrix, all entries are zeros, of size
3
×
3
3 \times 3
3
×
3
. Let ``` P = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] Q = [[1, 1, -1], [1, 1, -1], [1, 1, -1]] R = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] ``` What is the output of the following snippet of code? ``` val = 0 for i in range(3): for j in range(3): R[i][j] = P[i][j] * Q[i][j] val = val + R[i][j] print(val) ```
Numerical
MEDIUM
4 marks
16 October 2022
13
Select all matrices `M` for which the following code prints `True` to the console. ``` # Look at the options for the value of M n = len(M) flag = True for i in range(n): for j in range(n): if (i != j) and (M[i][j] != M[j][i]): flag = False print(flag) ```
Multiple correct
MEDIUM
4 marks
05 June 2022
14
`M` is a matrix, represented as a list of lists, that has already been defined. The dimension of `M` is
m
i
m
e
s
n
m imes n
mim
es
n
. Assume that both
m
m
m
and
n
n
n
are greater than or equal to
2
2
2
and all elements of `M` are integers. Select all correct options about the code given below. ``` # M is a matrix (list of lists) that has already been defined n = len(M[0]) flag = True for i in range(n): if M[0][i] - M[-1][i] != 1: flag = False print(flag) ```
Multiple correct
MEDIUM
4 marks
05 June 2022
Showing 14 questions.