Prasnya
Prasnya
Prasnya
Continue with Google
Prasnya
Continue with Google
Week 4 Programming in Python Questions | Prasnya
Programming in Python > Week 4
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
25Q
01
Consider the following Python code. How many lines will be printed when this code is executed? ``` for i in range(1, 5): for j in range(1, 5): if j == 3: break if i == 2: continue print(i, j) ```
Numerical
MEDIUM
3 marks
26 October 2025
02
Consider a Python program that takes a sentence, which may contain both uppercase and lowercase letters, spaces, and punctuation, and prints the number of vowels present. Snippet-1: ``` sentence = input() count = 0 vowels = set("aeiouAEIOU") for char in sentence: if char in vowels: count += 1 print(count) ``` Snippet-2: ``` sentence = input() count = 0 for char in sentence.lower(): if char in ['a', 'e', 'i', 'o', 'u']: count += 1 print(count) ``` Which of these two snippets is correct?
Single correct
EASY
3 marks
13 July 2025
03
What is the output of the following snippet of code? Enter an integer as your answer. ``` lst = [x for x in [1, 0, -2]] result = 0 for val in lst: if val == 0: result += 10 elif val < 0: result += 5 elif val % 2 == 1: result += 3 else: result += 1 print(result) ```
Numerical
MEDIUM
4 marks
13 July 2025
04
Write a `while` loop to print the first
100
100
100
powers of
3
3
3
, one on each line. The
i
i
i
-th line should have the value of
3
i
3^i
3
i
. The output has
100
100
100
lines in total. The first five lines look like this: ``` 3 9 27 81 243 ```
Single correct
EASY
3 marks
23 February 2025
05
Select all inputs for which this code will print the value `True` to the console. The input will only contain letters. ``` word = input() x = 0 y = 0 for char in word: # z is in lower case in the if-block given below if 'a' <= char <= 'z': x += 1 # Z is in upper case in the if-block given below if 'A' <= char <= 'Z': y += 1 if x > y: print(True) else: print(False) ```
Multiple correct
MEDIUM
4 marks
23 February 2025
06
Consider the following snippet of code. Assume that `1234` is passed as input to the code. What will be the output? ``` num = int(input("Enter a number")) s_num = 1 while num != 0: digit = num % 10 s_num = s_num * digit num //= 10 print(s_num) ```
Numerical
MEDIUM
3 marks
23 February 2025
07
What will be the output if the `pass` is replaced with `break` in the given code?
Comprehension
EASY
1 marks
23 February 2025
08
What will be the output if the `pass` is replaced with `continue` in the given code?
Comprehension
EASY
1 marks
23 February 2025
09
Consider the given program. ``` words = input().split() value = 0 for word in words: value += max(min(len(word), 12), 9) print(value) ``` What is the output of the above code for the input `"The extraordinary performance"`? Enter an integer as your answer.
Numerical
MEDIUM
3 marks
27 October 2024
10
What will be the output of the following code snippet? Enter an integer as your answer. ``` result = 0 for i in range(1, 15): if i % 2 == 0: continue elif i % 5 == 0: break result += i print(result) ```
Numerical
MEDIUM
3 marks
27 October 2024
11
What is the second line of the output? Enter an integer as your answer.
Comprehension
EASY
3 marks
27 October 2024
12
Consider a program that accepts a word as input from the user and prints the number of punctuation marks in it. You can assume that the input will be given in lower case. Here we are considering only the given punctuation marks: `,`, `.`, `:`, `;`. Which of these two snippets is correct? Snippet-1: ``` word = input() count = 0 punctuation_marks = [',', '.', ':', ';'] for char in word: if char in punctuation_marks: count += 1 print(count) ``` Snippet-2: ``` word = input() count = 0 for char in word: if char in ',.:;': count += 1 print(count) ```
Single correct
EASY
3 marks
07 July 2024
13
Select all inputs for which the code below prints the value `True`. Each input is a sentence with a space between consecutive words, all of which are in lower case. ``` sentence = input() space = " " # one space between the quotes n = len(sentence) # all letters in vowels are in lower case vowels = 'aeiou' surprise = True for char in vowels: if char not in sentence: surprise = False break print(surprise) ```
Multiple correct
MEDIUM
3 marks
07 July 2024
14
Consider the following snippet of code. Assume that `1234` is passed as input to the code. What will be the output? ``` num = int(input("Enter a number")) s_num = 1 while num != 0: digit = num % 10 s_num = s_num + digit num //= 10 print(s_num) ```
Numerical
MEDIUM
3 marks
07 July 2024
15
Select the correct code block.
Comprehension
MEDIUM
4 marks
29 October 2023
16
What is the value of `n` after executing the previous code? That is, once we get out of the while loop, what is the value of `n`?
Comprehension
EASY
2 marks
29 October 2023
17
Select an appropriate code snippet that can shift the given key `zanzamsayzam` by two places along the alphabet and generate the encrypted key.
Single correct
MEDIUM
4 marks
16 July 2023
18
Select an appropriate code snippet that calculates the sum of a series up to `n` terms. The series defined here for `n = 5` is:
1
+
12
+
123
+
1234
+
12345
=
13715
1 + 12 + 123 + 1234 + 12345 = 13715
1
+
12
+
123
+
1234
+
12345
=
13715
.
Single correct
MEDIUM
4 marks
16 July 2023
19
Consider the following Python snippet. Assume that
2345
2345
2345
is passed as input to the code. Which of the following option is the correct output for the given input? ``` num = int(input("Enter a number")) r_num = 1 while num != 0: digit = num % 10 r_num = r_num * 10 + digit num //= 10 print(r_num) ```
Single correct
MEDIUM
4 marks
16 July 2023
20
Select all the code snippets that print `Magic Number` if the number `n` leaves remainder
0
0
0
when divided by
7
7
7
but leaves remainder
1
1
1
when divided by
2
2
2
,
3
3
3
,
4
4
4
,
5
5
5
, and
6
6
6
. Otherwise, print `Not Magic Number`.
Single correct
MEDIUM
4 marks
16 July 2023
21
If `n` is a positive integer, what is the output of the following code? Assume that natural numbers start from
1
1
1
, that is,
0
0
0
is not a natural number. ``` a = n for i in range(1, n): a = a + i b = a for j in range(1, a): b = b * j print(b) ```
Single correct
MEDIUM
4 marks
16 October 2022
22
Which of the following options print the pair of strings `"Welcome to Python Quiz!"` and `"All the best!"` alternately on separate lines `n` times? There should be one blank line between two pairs and there should not be any space after the last pair. Here, `n` is a positive integer that has already been defined. Sample output for `n = 3`: ``` Welcome to Python Quiz! All the best! Welcome to Python Quiz! All the best! Welcome to Python Quiz! All the best! ```
Multiple correct
MEDIUM
4 marks
16 October 2022
23
For what values of `a`, `b`, and `c` does the code given below print a sequence which has
0
0
0
as one of the elements? ``` for i in range(a, b, c): print(i) ```
Multiple correct
MEDIUM
5 marks
16 October 2022
24
Select all inputs for which this code will print the value `True` to the console. The input will contain only letters. ``` word = input() x = 0 y = 0 for char in word: # z is in lower case in the if block given below if 'a' <= char <= 'z': x += 1 # Z is in upper case in the if block given below if 'A' <= char <= 'Z': y += 1 if x > y: print(True) else: print(False) ```
Multiple correct
EASY
4 marks
05 June 2022
25
`L` is a list of years. What is the output of the following snippet of code? ``` L = [1943, 2813, 2012, 1926, 1957, 2018, 1985, 2018, 1945, 1978, 2019, 1958, 2089, 1089, 1939, 2021] year_1 = 1988 year_2 = 2022 for year in L: if year < 2000: if year > year_1: year_1 = year else: if year < year_2: year_2 = year print(year_2 - year_1) ```
Numerical
MEDIUM
4 marks
05 June 2022
Showing 25 questions.
Programming in Python > Week 4
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
25Q
01
Consider the following Python code. How many lines will be printed when this code is executed? ``` for i in range(1, 5): for j in range(1, 5): if j == 3: break if i == 2: continue print(i, j) ```
Numerical
MEDIUM
3 marks
26 October 2025
02
Consider a Python program that takes a sentence, which may contain both uppercase and lowercase letters, spaces, and punctuation, and prints the number of vowels present. Snippet-1: ``` sentence = input() count = 0 vowels = set("aeiouAEIOU") for char in sentence: if char in vowels: count += 1 print(count) ``` Snippet-2: ``` sentence = input() count = 0 for char in sentence.lower(): if char in ['a', 'e', 'i', 'o', 'u']: count += 1 print(count) ``` Which of these two snippets is correct?
Single correct
EASY
3 marks
13 July 2025
03
What is the output of the following snippet of code? Enter an integer as your answer. ``` lst = [x for x in [1, 0, -2]] result = 0 for val in lst: if val == 0: result += 10 elif val < 0: result += 5 elif val % 2 == 1: result += 3 else: result += 1 print(result) ```
Numerical
MEDIUM
4 marks
13 July 2025
04
Write a `while` loop to print the first
100
100
100
powers of
3
3
3
, one on each line. The
i
i
i
-th line should have the value of
3
i
3^i
3
i
. The output has
100
100
100
lines in total. The first five lines look like this: ``` 3 9 27 81 243 ```
Single correct
EASY
3 marks
23 February 2025
05
Select all inputs for which this code will print the value `True` to the console. The input will only contain letters. ``` word = input() x = 0 y = 0 for char in word: # z is in lower case in the if-block given below if 'a' <= char <= 'z': x += 1 # Z is in upper case in the if-block given below if 'A' <= char <= 'Z': y += 1 if x > y: print(True) else: print(False) ```
Multiple correct
MEDIUM
4 marks
23 February 2025
06
Consider the following snippet of code. Assume that `1234` is passed as input to the code. What will be the output? ``` num = int(input("Enter a number")) s_num = 1 while num != 0: digit = num % 10 s_num = s_num * digit num //= 10 print(s_num) ```
Numerical
MEDIUM
3 marks
23 February 2025
07
What will be the output if the `pass` is replaced with `break` in the given code?
Comprehension
EASY
1 marks
23 February 2025
08
What will be the output if the `pass` is replaced with `continue` in the given code?
Comprehension
EASY
1 marks
23 February 2025
09
Consider the given program. ``` words = input().split() value = 0 for word in words: value += max(min(len(word), 12), 9) print(value) ``` What is the output of the above code for the input `"The extraordinary performance"`? Enter an integer as your answer.
Numerical
MEDIUM
3 marks
27 October 2024
10
What will be the output of the following code snippet? Enter an integer as your answer. ``` result = 0 for i in range(1, 15): if i % 2 == 0: continue elif i % 5 == 0: break result += i print(result) ```
Numerical
MEDIUM
3 marks
27 October 2024
11
What is the second line of the output? Enter an integer as your answer.
Comprehension
EASY
3 marks
27 October 2024
12
Consider a program that accepts a word as input from the user and prints the number of punctuation marks in it. You can assume that the input will be given in lower case. Here we are considering only the given punctuation marks: `,`, `.`, `:`, `;`. Which of these two snippets is correct? Snippet-1: ``` word = input() count = 0 punctuation_marks = [',', '.', ':', ';'] for char in word: if char in punctuation_marks: count += 1 print(count) ``` Snippet-2: ``` word = input() count = 0 for char in word: if char in ',.:;': count += 1 print(count) ```
Single correct
EASY
3 marks
07 July 2024
13
Select all inputs for which the code below prints the value `True`. Each input is a sentence with a space between consecutive words, all of which are in lower case. ``` sentence = input() space = " " # one space between the quotes n = len(sentence) # all letters in vowels are in lower case vowels = 'aeiou' surprise = True for char in vowels: if char not in sentence: surprise = False break print(surprise) ```
Multiple correct
MEDIUM
3 marks
07 July 2024
14
Consider the following snippet of code. Assume that `1234` is passed as input to the code. What will be the output? ``` num = int(input("Enter a number")) s_num = 1 while num != 0: digit = num % 10 s_num = s_num + digit num //= 10 print(s_num) ```
Numerical
MEDIUM
3 marks
07 July 2024
15
Select the correct code block.
Comprehension
MEDIUM
4 marks
29 October 2023
16
What is the value of `n` after executing the previous code? That is, once we get out of the while loop, what is the value of `n`?
Comprehension
EASY
2 marks
29 October 2023
17
Select an appropriate code snippet that can shift the given key `zanzamsayzam` by two places along the alphabet and generate the encrypted key.
Single correct
MEDIUM
4 marks
16 July 2023
18
Select an appropriate code snippet that calculates the sum of a series up to `n` terms. The series defined here for `n = 5` is:
1
+
12
+
123
+
1234
+
12345
=
13715
1 + 12 + 123 + 1234 + 12345 = 13715
1
+
12
+
123
+
1234
+
12345
=
13715
.
Single correct
MEDIUM
4 marks
16 July 2023
19
Consider the following Python snippet. Assume that
2345
2345
2345
is passed as input to the code. Which of the following option is the correct output for the given input? ``` num = int(input("Enter a number")) r_num = 1 while num != 0: digit = num % 10 r_num = r_num * 10 + digit num //= 10 print(r_num) ```
Single correct
MEDIUM
4 marks
16 July 2023
20
Select all the code snippets that print `Magic Number` if the number `n` leaves remainder
0
0
0
when divided by
7
7
7
but leaves remainder
1
1
1
when divided by
2
2
2
,
3
3
3
,
4
4
4
,
5
5
5
, and
6
6
6
. Otherwise, print `Not Magic Number`.
Single correct
MEDIUM
4 marks
16 July 2023
21
If `n` is a positive integer, what is the output of the following code? Assume that natural numbers start from
1
1
1
, that is,
0
0
0
is not a natural number. ``` a = n for i in range(1, n): a = a + i b = a for j in range(1, a): b = b * j print(b) ```
Single correct
MEDIUM
4 marks
16 October 2022
22
Which of the following options print the pair of strings `"Welcome to Python Quiz!"` and `"All the best!"` alternately on separate lines `n` times? There should be one blank line between two pairs and there should not be any space after the last pair. Here, `n` is a positive integer that has already been defined. Sample output for `n = 3`: ``` Welcome to Python Quiz! All the best! Welcome to Python Quiz! All the best! Welcome to Python Quiz! All the best! ```
Multiple correct
MEDIUM
4 marks
16 October 2022
23
For what values of `a`, `b`, and `c` does the code given below print a sequence which has
0
0
0
as one of the elements? ``` for i in range(a, b, c): print(i) ```
Multiple correct
MEDIUM
5 marks
16 October 2022
24
Select all inputs for which this code will print the value `True` to the console. The input will contain only letters. ``` word = input() x = 0 y = 0 for char in word: # z is in lower case in the if block given below if 'a' <= char <= 'z': x += 1 # Z is in upper case in the if block given below if 'A' <= char <= 'Z': y += 1 if x > y: print(True) else: print(False) ```
Multiple correct
EASY
4 marks
05 June 2022
25
`L` is a list of years. What is the output of the following snippet of code? ``` L = [1943, 2813, 2012, 1926, 1957, 2018, 1985, 2018, 1945, 1978, 2019, 1958, 2089, 1089, 1939, 2021] year_1 = 1988 year_2 = 2022 for year in L: if year < 2000: if year > year_1: year_1 = year else: if year < year_2: year_2 = year print(year_2 - year_1) ```
Numerical
MEDIUM
4 marks
05 June 2022
Showing 25 questions.