Prasnya
Prasnya
Prasnya
Continue with Google
Prasnya
Continue with Google
Week 5 Programming in Python Questions | Prasnya
Programming in Python > Week 5
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
14Q
01
Consider the following Python code. How many lines will be printed when this code is executed? ``` for i in range(1, 6): for j in range(1, 6): for k in range(1, 2): if i == j: print("-") else: print("*", end=" ") print("+") ```
Numerical
MEDIUM
4 marks
26 October 2025
02
How many times is the inner `for x in item` loop executed in total when running `analyze(sample)`?
Comprehension
MEDIUM
4 marks
26 October 2025
03
We want to print the following pattern: ``` 1111 1001 1011 1111 ``` Which of these two snippets is correct? Snippet-1: ``` n = 4 for i in range(n): for j in range(n): if i == 0 or i == n - 1 or j == 0 or j == n - 1: print('1', end='') elif i == j: print('1', end='') else: print('0', end='') print() ``` Snippet-2: ``` n = 4 for i in range(n): row = '' for j in range(n): if i in [0, n - 1] or j in [0, n - 1]: row += '1' elif i == j: row += '0' else: row += '1' print(row) ```
Single correct
MEDIUM
4 marks
13 July 2025
04
Consider the following Python code: ``` def process(x, y): if x > y: return x - y elif x < y: return y - x else: return x + y def compute(a, b): result = process(a, b) if result % 2 == 0: return "Even" else: return "Odd" ``` Which of the following statements is/are true?
Multiple correct
EASY
4 marks
13 July 2025
05
Consider the following snippet of code. What will the output be? ``` result = 0 for i in range(1, 4): for j in range(1, 4): if i == j: continue if i + j > 4: break result += i + j print(result) ```
Numerical
MEDIUM
3 marks
13 July 2025
06
We wish to print the following pattern: ``` 00000 01110 01110 01110 00000 ``` Which of the two snippets is correct? Snippet-1: ``` n = 5 zero = '0' # len(zero) == 1 one = '1' # len(one) == 1 for i in range(n): if i == 0 or i == n - 1: print(zero * n) else: print(zero + one * (n - 2) + zero) ``` Snippet-2: ``` n = 5 zero = '0' # len(zero) == 1 one = '1' # len(one) == 1 for i in range(n): for j in range(n): if j == 0 or j == n - 1: print(one, end='') # end argument is an empty string else: print(zero, end='') # end argument is an empty string print() ``` Useful information - Input: ``` print('1', end='') # end argument is an empty string print('2', end='') # end argument is an empty string print() print('3' * 5) ``` Useful information - Output: ``` 12 33333 ```
Single correct
MEDIUM
3 marks
07 July 2024
07
What is the output of the following snippet of code? ``` c1 = 0 c2 = 0 for x in range(1, 101): for y in range(1, 101): if x + y == 199: c1 = c1 + 1 c2 = c2 + 1 print(c2 // c1) ```
Numerical
MEDIUM
3 marks
29 October 2023
08
What will be the output of the code snippet given below? ``` a = 5 b = 5 for x in range(0, a): for y in range(b, x - 1, -1): print(y, end=' ') print() ```
Single correct
MEDIUM
3 marks
16 July 2023
09
Select all correct implementations of a program that prints the first
10
10
10
prime numbers to the console, one number on each line. The first
10
10
10
prime numbers are less than
30
30
30
and the
11
11
11
th prime number is more than
30
30
30
.
Multiple correct
HARD
4 marks
16 July 2023
10
If `n` is a positive integer, then what will be the value of `count` at the end of execution of the code given below? ``` n = int(input()) count = 0 for x in range(1, n + 1): for y in range(x + 1, n + 1): count = count + 1 ```
Single correct
MEDIUM
3 marks
16 October 2022
11
Select all snippets of code that print the following sequence of `n` lines, where `n` is a positive integer that is already defined. The
i
i
i
th line in the output corresponds to the first
i
i
i
Fibonacci numbers, for
1
≤
i
≤
n
1 \le i \le n
1
≤
i
≤
n
. Assume that
0
0
0
and
1
1
1
are the first two Fibonacci numbers. There should be a single space after every number, including after the last number in any given line. Sample output for `n = 7`: ``` 0 0 1 0 1 1 0 1 1 2 0 1 1 2 3 0 1 1 2 3 5 0 1 1 2 3 5 8 ```
Multiple correct
HARD
5 marks
16 October 2022
12
If `n` is a positive integer, what is the value of `count` at the end of execution of the code given below? ``` n = int(input()) count = 0 for x in range(1, n + 1): for y in range(x + 1, n + 1): count = count + 1 ```
Single correct
MEDIUM
3 marks
05 June 2022
13
The following code always accepts a positive even integer as input. What is the output produced by the code if the input is `1999999978`? Hint: `999999989` is a prime number. ``` n = int(input()) f = n - 2 while (f >= 0) and (n % f != 0): f = f - 2 print(f) ```
Numerical
HARD
4 marks
05 June 2022
14
What is the output of the following snippet of code? ``` a, b = 8, 28 if a < b: start = b else: start = a end = a * b for x in range(start, end + 1): if (x % a == 0) and (x % b == 0): print(x) break ```
Numerical
MEDIUM
4 marks
05 June 2022
Showing 14 questions.
Programming in Python > Week 5
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
14Q
01
Consider the following Python code. How many lines will be printed when this code is executed? ``` for i in range(1, 6): for j in range(1, 6): for k in range(1, 2): if i == j: print("-") else: print("*", end=" ") print("+") ```
Numerical
MEDIUM
4 marks
26 October 2025
02
How many times is the inner `for x in item` loop executed in total when running `analyze(sample)`?
Comprehension
MEDIUM
4 marks
26 October 2025
03
We want to print the following pattern: ``` 1111 1001 1011 1111 ``` Which of these two snippets is correct? Snippet-1: ``` n = 4 for i in range(n): for j in range(n): if i == 0 or i == n - 1 or j == 0 or j == n - 1: print('1', end='') elif i == j: print('1', end='') else: print('0', end='') print() ``` Snippet-2: ``` n = 4 for i in range(n): row = '' for j in range(n): if i in [0, n - 1] or j in [0, n - 1]: row += '1' elif i == j: row += '0' else: row += '1' print(row) ```
Single correct
MEDIUM
4 marks
13 July 2025
04
Consider the following Python code: ``` def process(x, y): if x > y: return x - y elif x < y: return y - x else: return x + y def compute(a, b): result = process(a, b) if result % 2 == 0: return "Even" else: return "Odd" ``` Which of the following statements is/are true?
Multiple correct
EASY
4 marks
13 July 2025
05
Consider the following snippet of code. What will the output be? ``` result = 0 for i in range(1, 4): for j in range(1, 4): if i == j: continue if i + j > 4: break result += i + j print(result) ```
Numerical
MEDIUM
3 marks
13 July 2025
06
We wish to print the following pattern: ``` 00000 01110 01110 01110 00000 ``` Which of the two snippets is correct? Snippet-1: ``` n = 5 zero = '0' # len(zero) == 1 one = '1' # len(one) == 1 for i in range(n): if i == 0 or i == n - 1: print(zero * n) else: print(zero + one * (n - 2) + zero) ``` Snippet-2: ``` n = 5 zero = '0' # len(zero) == 1 one = '1' # len(one) == 1 for i in range(n): for j in range(n): if j == 0 or j == n - 1: print(one, end='') # end argument is an empty string else: print(zero, end='') # end argument is an empty string print() ``` Useful information - Input: ``` print('1', end='') # end argument is an empty string print('2', end='') # end argument is an empty string print() print('3' * 5) ``` Useful information - Output: ``` 12 33333 ```
Single correct
MEDIUM
3 marks
07 July 2024
07
What is the output of the following snippet of code? ``` c1 = 0 c2 = 0 for x in range(1, 101): for y in range(1, 101): if x + y == 199: c1 = c1 + 1 c2 = c2 + 1 print(c2 // c1) ```
Numerical
MEDIUM
3 marks
29 October 2023
08
What will be the output of the code snippet given below? ``` a = 5 b = 5 for x in range(0, a): for y in range(b, x - 1, -1): print(y, end=' ') print() ```
Single correct
MEDIUM
3 marks
16 July 2023
09
Select all correct implementations of a program that prints the first
10
10
10
prime numbers to the console, one number on each line. The first
10
10
10
prime numbers are less than
30
30
30
and the
11
11
11
th prime number is more than
30
30
30
.
Multiple correct
HARD
4 marks
16 July 2023
10
If `n` is a positive integer, then what will be the value of `count` at the end of execution of the code given below? ``` n = int(input()) count = 0 for x in range(1, n + 1): for y in range(x + 1, n + 1): count = count + 1 ```
Single correct
MEDIUM
3 marks
16 October 2022
11
Select all snippets of code that print the following sequence of `n` lines, where `n` is a positive integer that is already defined. The
i
i
i
th line in the output corresponds to the first
i
i
i
Fibonacci numbers, for
1
≤
i
≤
n
1 \le i \le n
1
≤
i
≤
n
. Assume that
0
0
0
and
1
1
1
are the first two Fibonacci numbers. There should be a single space after every number, including after the last number in any given line. Sample output for `n = 7`: ``` 0 0 1 0 1 1 0 1 1 2 0 1 1 2 3 0 1 1 2 3 5 0 1 1 2 3 5 8 ```
Multiple correct
HARD
5 marks
16 October 2022
12
If `n` is a positive integer, what is the value of `count` at the end of execution of the code given below? ``` n = int(input()) count = 0 for x in range(1, n + 1): for y in range(x + 1, n + 1): count = count + 1 ```
Single correct
MEDIUM
3 marks
05 June 2022
13
The following code always accepts a positive even integer as input. What is the output produced by the code if the input is `1999999978`? Hint: `999999989` is a prime number. ``` n = int(input()) f = n - 2 while (f >= 0) and (n % f != 0): f = f - 2 print(f) ```
Numerical
HARD
4 marks
05 June 2022
14
What is the output of the following snippet of code? ``` a, b = 8, 28 if a < b: start = b else: start = a end = a * b for x in range(start, end + 1): if (x % a == 0) and (x % b == 0): print(x) break ```
Numerical
MEDIUM
4 marks
05 June 2022
Showing 14 questions.