Prasnya
Prasnya
Prasnya
Continue with Google
Prasnya
Continue with Google
Week 6 Programming in Python Questions | Prasnya
Programming in Python > Week 6
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
37Q
01
Consider the following Python code. What will the value stored in `x` be at the end of the program execution? ``` x = 5 x = x + 2.0 x = str(x) + "3" x = x * 2 x = [x] x = x + [10] ```
Single correct
MEDIUM
3 marks
26 October 2025
02
Consider the following Python code. Which of the following statements are valid? Select all that apply. ``` t = (5, [10, 20], (30, [40, 50], (30,))) ```
Multiple correct
MEDIUM
4 marks
26 October 2025
03
What is the value of `output` after executing the given code?
Comprehension
MEDIUM
4 marks
26 October 2025
04
What is the output of the following Python code? ``` data = ["alpha", "beta", "gamma"] data[1] = data[1].replace("e", data[0][1]) data[2] = data[2][::-1].replace("a", data[1][3]) print(data) ```
Single correct
MEDIUM
3 marks
13 July 2025
05
`P` is a non-empty list of distinct integers that has already been defined. Which of the following statements are true at the end of execution of the code given below? ``` Q, R = [], [] for x in P: Q.append(-x) Q.sort() for x in Q: R.append(-x) ```
Multiple correct
MEDIUM
4 marks
13 July 2025
06
What is the output of the following snippet of code? Enter an integer as your answer. ``` lst = ['IIT', ['Madras', '2025'], 'exam'] print(len(lst[0]) + len(lst[1][1]) + len(lst[2])) ```
Numerical
EASY
4 marks
13 July 2025
07
Consider the following snippet of code. What will the output be? ``` names = ["alice", "bob", "charlie", "david", "eve"] result = 0 short = [] for name in names: if len(name) < 4: short.append(name) elif len(name) == 5: result += 1 elif 'a' in name: result += 2 print(len(short) + result) ```
Numerical
MEDIUM
4 marks
13 July 2025
08
What is the value of `output` after executing the given code?
Comprehension
EASY
4 marks
13 July 2025
09
Which of the following changes would also include `SQL` in the final result?
Comprehension
MEDIUM
3 marks
13 July 2025
10
What is the output of the following snippet of code? ``` L = ['Delhi', 'Mumbai', 'Chennai', 'Bengaluru'] out = [] while L != []: mini = len(L[0]) city = L[0] for name in L: if len(name) < mini: mini = len(name) city = name out.append(city) # L.remove(city) removes the city from the list L L.remove(city) print(out) ```
Single correct
MEDIUM
3 marks
23 February 2025
11
Consider the following snippet of code. What will the output be? ``` val = 0 L = [9, 1, 5, 4, 2] temp = [] for num in L: if num % 2 != 0: temp.append(num) else: val += num print(len(temp) * val) ```
Numerical
MEDIUM
3 marks
23 February 2025
12
What will be the first line of output?
Comprehension
EASY
3 marks
23 February 2025
13
What will be the second line of output?
Comprehension
EASY
3 marks
23 February 2025
14
Consider a program that wants to find the number of vowels in each word of a sentence and create a list. Choose the correct implementation from the following set of code snippets. Snippet-1: ``` sentence = input() vowels = "aeiouAEIOU" words = sentence.split() vowel_counts = [] for word in words: count = 0 for char in word: if char in vowels: count += 1 vowel_counts.append(count) print(vowel_counts) ``` Snippet-2: ``` sentence = input() vowels = set("aeiouAEIOU") words = sentence.split() vowel_counts = [] for word in words: count = len(set(word).intersection(vowels)) vowel_counts.append(count) print(vowel_counts) ``` Snippet-3: ``` sentence = input() vowels = "aeiou" words = sentence.split() vowel_counts = [] for word in words: word = word.lower() count = 0 for char in word: count += 1 if char in vowels else 0 vowel_counts.append(count) print(vowel_counts) ``` Snippet-4: ``` sentence = input().split() vowel_counts = [] for word in sentence: word = word.upper() count = 0 for char in word: if char in 'AEIOU': count += 1 vowel_counts.append(count) print(vowel_counts) ```
Single correct
MEDIUM
3 marks
27 October 2024
15
Which of the below code snippets produces the following output? ``` [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3]] ```
Multiple correct
MEDIUM
3 marks
27 October 2024
16
What is the first line of output for
n
=
5
n = 5
n
=
5
?
Comprehension
MEDIUM
3 marks
27 October 2024
17
What is the second line of the output for
n
=
5
n = 5
n
=
5
? Enter an integer as your answer.
Comprehension
MEDIUM
3 marks
27 October 2024
18
What is the first line of output?
Comprehension
MEDIUM
3 marks
27 October 2024
19
What is the first line of output?
Comprehension
MEDIUM
3 marks
27 October 2024
20
What is the second line of the output? Enter an integer as your answer.
Comprehension
EASY
2 marks
27 October 2024
21
Consider the following snippet of code. What will the output be? ``` val = 0 L = [7, 1, 8, 3, 10] temp = [] for num in L: if num % 2 == 0: temp.append(num) else: val += num print(len(temp) * val) ```
Numerical
MEDIUM
3 marks
07 July 2024
22
What is the first line of output?
Comprehension
EASY
3 marks
07 July 2024
23
What is the second line of the output? Enter an integer as your answer.
Comprehension
EASY
3 marks
07 July 2024
24
What will be the output?
Comprehension
EASY
3 marks
07 July 2024
25
Choose the correct option regarding the given code.
Comprehension
EASY
3 marks
07 July 2024
26
What is the output of the following snippet of code? ``` L = ['four', 'one', 'ninety', 'three'] out = [] while L != []: mini = len(L[0]) word = L[0] for number in L: if len(number) < mini: mini = len(number) word = number out.append(word) # L.remove(word) removes word from the list L L.remove(word) print(out) ```
Single correct
MEDIUM
4 marks
29 October 2023
27
Note: The index starts from
0
0
0
in lists. `l1` is a non-empty list of integers. What is the output of the following snippet of code? ``` # Hint: str(3) is '3' l2 = [] for i in range(len(l1)): condition_1 = not (i % 2 == 0) condition_2 = not (len(str(l1[i])) != 3) if condition_1 and condition_2: l2.append(l1[i]) print(len(l2)) ```
Single correct
MEDIUM
4 marks
29 October 2023
28
What is the output of the following snippet of code? ``` # Hint: negative indexing in lists works # in the same way as negative indexing in strings # so L[-1] is 5 and L[-2] is 4 and so on L = [1, 2, 3, 4, 5] stop = -len(L) - 1 x = 0 i = -1 while i > stop: x = x * 10 + L[i] i = i - 1 print(x) ```
Numerical
MEDIUM
4 marks
29 October 2023
29
What will be the output of the code snippet given below? ``` L = [-1, 1] for i in range(8): size = len(L) value = (L[size - 2] + L[size - 1]) * 2 L.append(value) print(L) ```
Single correct
MEDIUM
4 marks
16 July 2023
30
Reverse a sentence based on words. The
i
i
i
th word from the left in the input sentence is the
i
i
i
th word from the end in the output sentence. Choose all options that accept a sentence as input and print the modified sentence. Example: ``` sentence = "i know how to code in python" modified_sentence = "python in code to how know i" ```
Multiple correct
MEDIUM
5 marks
16 July 2023
31
`L` is a non-empty list of distinct positive integers. If the following snippet of code terminates without any error after a finite number of iterations of the `while` loop, what is the output produced by it? Hint: `L.remove(x)` removes the leftmost occurrence of `x` in `L`. ``` # L is a non-empty list of distinct positive integers # L has already been defined val = 0 for x in L: val += x while L != []: for y in range(1, 11, 2): if y in L: L.remove(y) else: L.append(y) print(val) ```
Numerical
HARD
3 marks
16 July 2023
32
What will be the output of the code snippet given below? ``` L = [0] for i in range(1, 10): size = len(L) value = i + L[size - 1] L.append(value) print(L) ```
Single correct
EASY
4 marks
16 October 2022
33
`L` is a non-empty list of positive integers that is already defined. Consider the following snippet of code: ``` flag1, flag2 = True, True for i in range(1, len(L)): if L[i] > L[i - 1]: flag2 = False elif L[i] < L[i - 1]: flag1 = False if flag1: print('one') elif flag2: print('two') else: print('three') ``` What is the output of the code if `L = [296, 288, 120, 710, 50, 27, 15]`?
Single correct
MEDIUM
4 marks
16 October 2022
34
Reverse a sentence based on words. The
i
i
i
th word from the left in the input sentence is the
i
i
i
th word from the end in the output sentence. Consider the following example: ``` sentence = "I know how to code in Python" modified_sentence = "Python in code to how know I" ``` Choose all the options that accept a sentence as input and print the modified sentence.
Multiple correct
MEDIUM
4 marks
16 October 2022
35
What is the output of the following snippet of code? All words in the list `L` are in lower case. ``` L = ['good', 'done', 'eat', 'trim', 'make', 'fake', 'ease', 'epic', 'cage', 'list', 'tog', 'got'] # L[0][-1] is the last letter of the first word counts = [] count = 1 for i in range(1, len(L)): if L[i - 1][-1] == L[i][0]: count += 1 else: counts.append(count) count = 1 counts.append(count) print(counts) ```
Single correct
MEDIUM
4 marks
05 June 2022
36
What is the output of the following snippet of code? ``` code = ['# this is a python code', 'x = 0', 'print(x)', 'for i in range(x):', ' x = x + 1', 'print(x)'] mod_code = [] for line in code: if 'print' in line: # there is a single space between the middle quotes line = '#' + ' ' + line mod_code.append(line) for line in mod_code: print(line) ```
Single correct
MEDIUM
4 marks
05 June 2022
37
`L` is a non-empty list of distinct positive integers. If the following code snippet terminates without any error after a finite number of iterations of the `while` loop, what is the output produced by it? Hint: `L.remove(x)` removes the leftmost occurrence of `x` in `L`. ``` # L is a non-empty list of distinct positive integers # L has already been defined val = 0 for x in L: val += x while L != []: for y in range(1, 11): if y in L: L.remove(y) else: L.append(y) print(val) ```
Numerical
HARD
3 marks
05 June 2022
Showing 37 questions.
Programming in Python > Week 6
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
37Q
01
Consider the following Python code. What will the value stored in `x` be at the end of the program execution? ``` x = 5 x = x + 2.0 x = str(x) + "3" x = x * 2 x = [x] x = x + [10] ```
Single correct
MEDIUM
3 marks
26 October 2025
02
Consider the following Python code. Which of the following statements are valid? Select all that apply. ``` t = (5, [10, 20], (30, [40, 50], (30,))) ```
Multiple correct
MEDIUM
4 marks
26 October 2025
03
What is the value of `output` after executing the given code?
Comprehension
MEDIUM
4 marks
26 October 2025
04
What is the output of the following Python code? ``` data = ["alpha", "beta", "gamma"] data[1] = data[1].replace("e", data[0][1]) data[2] = data[2][::-1].replace("a", data[1][3]) print(data) ```
Single correct
MEDIUM
3 marks
13 July 2025
05
`P` is a non-empty list of distinct integers that has already been defined. Which of the following statements are true at the end of execution of the code given below? ``` Q, R = [], [] for x in P: Q.append(-x) Q.sort() for x in Q: R.append(-x) ```
Multiple correct
MEDIUM
4 marks
13 July 2025
06
What is the output of the following snippet of code? Enter an integer as your answer. ``` lst = ['IIT', ['Madras', '2025'], 'exam'] print(len(lst[0]) + len(lst[1][1]) + len(lst[2])) ```
Numerical
EASY
4 marks
13 July 2025
07
Consider the following snippet of code. What will the output be? ``` names = ["alice", "bob", "charlie", "david", "eve"] result = 0 short = [] for name in names: if len(name) < 4: short.append(name) elif len(name) == 5: result += 1 elif 'a' in name: result += 2 print(len(short) + result) ```
Numerical
MEDIUM
4 marks
13 July 2025
08
What is the value of `output` after executing the given code?
Comprehension
EASY
4 marks
13 July 2025
09
Which of the following changes would also include `SQL` in the final result?
Comprehension
MEDIUM
3 marks
13 July 2025
10
What is the output of the following snippet of code? ``` L = ['Delhi', 'Mumbai', 'Chennai', 'Bengaluru'] out = [] while L != []: mini = len(L[0]) city = L[0] for name in L: if len(name) < mini: mini = len(name) city = name out.append(city) # L.remove(city) removes the city from the list L L.remove(city) print(out) ```
Single correct
MEDIUM
3 marks
23 February 2025
11
Consider the following snippet of code. What will the output be? ``` val = 0 L = [9, 1, 5, 4, 2] temp = [] for num in L: if num % 2 != 0: temp.append(num) else: val += num print(len(temp) * val) ```
Numerical
MEDIUM
3 marks
23 February 2025
12
What will be the first line of output?
Comprehension
EASY
3 marks
23 February 2025
13
What will be the second line of output?
Comprehension
EASY
3 marks
23 February 2025
14
Consider a program that wants to find the number of vowels in each word of a sentence and create a list. Choose the correct implementation from the following set of code snippets. Snippet-1: ``` sentence = input() vowels = "aeiouAEIOU" words = sentence.split() vowel_counts = [] for word in words: count = 0 for char in word: if char in vowels: count += 1 vowel_counts.append(count) print(vowel_counts) ``` Snippet-2: ``` sentence = input() vowels = set("aeiouAEIOU") words = sentence.split() vowel_counts = [] for word in words: count = len(set(word).intersection(vowels)) vowel_counts.append(count) print(vowel_counts) ``` Snippet-3: ``` sentence = input() vowels = "aeiou" words = sentence.split() vowel_counts = [] for word in words: word = word.lower() count = 0 for char in word: count += 1 if char in vowels else 0 vowel_counts.append(count) print(vowel_counts) ``` Snippet-4: ``` sentence = input().split() vowel_counts = [] for word in sentence: word = word.upper() count = 0 for char in word: if char in 'AEIOU': count += 1 vowel_counts.append(count) print(vowel_counts) ```
Single correct
MEDIUM
3 marks
27 October 2024
15
Which of the below code snippets produces the following output? ``` [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3]] ```
Multiple correct
MEDIUM
3 marks
27 October 2024
16
What is the first line of output for
n
=
5
n = 5
n
=
5
?
Comprehension
MEDIUM
3 marks
27 October 2024
17
What is the second line of the output for
n
=
5
n = 5
n
=
5
? Enter an integer as your answer.
Comprehension
MEDIUM
3 marks
27 October 2024
18
What is the first line of output?
Comprehension
MEDIUM
3 marks
27 October 2024
19
What is the first line of output?
Comprehension
MEDIUM
3 marks
27 October 2024
20
What is the second line of the output? Enter an integer as your answer.
Comprehension
EASY
2 marks
27 October 2024
21
Consider the following snippet of code. What will the output be? ``` val = 0 L = [7, 1, 8, 3, 10] temp = [] for num in L: if num % 2 == 0: temp.append(num) else: val += num print(len(temp) * val) ```
Numerical
MEDIUM
3 marks
07 July 2024
22
What is the first line of output?
Comprehension
EASY
3 marks
07 July 2024
23
What is the second line of the output? Enter an integer as your answer.
Comprehension
EASY
3 marks
07 July 2024
24
What will be the output?
Comprehension
EASY
3 marks
07 July 2024
25
Choose the correct option regarding the given code.
Comprehension
EASY
3 marks
07 July 2024
26
What is the output of the following snippet of code? ``` L = ['four', 'one', 'ninety', 'three'] out = [] while L != []: mini = len(L[0]) word = L[0] for number in L: if len(number) < mini: mini = len(number) word = number out.append(word) # L.remove(word) removes word from the list L L.remove(word) print(out) ```
Single correct
MEDIUM
4 marks
29 October 2023
27
Note: The index starts from
0
0
0
in lists. `l1` is a non-empty list of integers. What is the output of the following snippet of code? ``` # Hint: str(3) is '3' l2 = [] for i in range(len(l1)): condition_1 = not (i % 2 == 0) condition_2 = not (len(str(l1[i])) != 3) if condition_1 and condition_2: l2.append(l1[i]) print(len(l2)) ```
Single correct
MEDIUM
4 marks
29 October 2023
28
What is the output of the following snippet of code? ``` # Hint: negative indexing in lists works # in the same way as negative indexing in strings # so L[-1] is 5 and L[-2] is 4 and so on L = [1, 2, 3, 4, 5] stop = -len(L) - 1 x = 0 i = -1 while i > stop: x = x * 10 + L[i] i = i - 1 print(x) ```
Numerical
MEDIUM
4 marks
29 October 2023
29
What will be the output of the code snippet given below? ``` L = [-1, 1] for i in range(8): size = len(L) value = (L[size - 2] + L[size - 1]) * 2 L.append(value) print(L) ```
Single correct
MEDIUM
4 marks
16 July 2023
30
Reverse a sentence based on words. The
i
i
i
th word from the left in the input sentence is the
i
i
i
th word from the end in the output sentence. Choose all options that accept a sentence as input and print the modified sentence. Example: ``` sentence = "i know how to code in python" modified_sentence = "python in code to how know i" ```
Multiple correct
MEDIUM
5 marks
16 July 2023
31
`L` is a non-empty list of distinct positive integers. If the following snippet of code terminates without any error after a finite number of iterations of the `while` loop, what is the output produced by it? Hint: `L.remove(x)` removes the leftmost occurrence of `x` in `L`. ``` # L is a non-empty list of distinct positive integers # L has already been defined val = 0 for x in L: val += x while L != []: for y in range(1, 11, 2): if y in L: L.remove(y) else: L.append(y) print(val) ```
Numerical
HARD
3 marks
16 July 2023
32
What will be the output of the code snippet given below? ``` L = [0] for i in range(1, 10): size = len(L) value = i + L[size - 1] L.append(value) print(L) ```
Single correct
EASY
4 marks
16 October 2022
33
`L` is a non-empty list of positive integers that is already defined. Consider the following snippet of code: ``` flag1, flag2 = True, True for i in range(1, len(L)): if L[i] > L[i - 1]: flag2 = False elif L[i] < L[i - 1]: flag1 = False if flag1: print('one') elif flag2: print('two') else: print('three') ``` What is the output of the code if `L = [296, 288, 120, 710, 50, 27, 15]`?
Single correct
MEDIUM
4 marks
16 October 2022
34
Reverse a sentence based on words. The
i
i
i
th word from the left in the input sentence is the
i
i
i
th word from the end in the output sentence. Consider the following example: ``` sentence = "I know how to code in Python" modified_sentence = "Python in code to how know I" ``` Choose all the options that accept a sentence as input and print the modified sentence.
Multiple correct
MEDIUM
4 marks
16 October 2022
35
What is the output of the following snippet of code? All words in the list `L` are in lower case. ``` L = ['good', 'done', 'eat', 'trim', 'make', 'fake', 'ease', 'epic', 'cage', 'list', 'tog', 'got'] # L[0][-1] is the last letter of the first word counts = [] count = 1 for i in range(1, len(L)): if L[i - 1][-1] == L[i][0]: count += 1 else: counts.append(count) count = 1 counts.append(count) print(counts) ```
Single correct
MEDIUM
4 marks
05 June 2022
36
What is the output of the following snippet of code? ``` code = ['# this is a python code', 'x = 0', 'print(x)', 'for i in range(x):', ' x = x + 1', 'print(x)'] mod_code = [] for line in code: if 'print' in line: # there is a single space between the middle quotes line = '#' + ' ' + line mod_code.append(line) for line in mod_code: print(line) ```
Single correct
MEDIUM
4 marks
05 June 2022
37
`L` is a non-empty list of distinct positive integers. If the following code snippet terminates without any error after a finite number of iterations of the `while` loop, what is the output produced by it? Hint: `L.remove(x)` removes the leftmost occurrence of `x` in `L`. ``` # L is a non-empty list of distinct positive integers # L has already been defined val = 0 for x in L: val += x while L != []: for y in range(1, 11): if y in L: L.remove(y) else: L.append(y) print(val) ```
Numerical
HARD
3 marks
05 June 2022
Showing 37 questions.