Prasnya
Prasnya
Prasnya
Continue with Google
Prasnya
Continue with Google
Week 2 Programming in Python Questions | Prasnya
Programming in Python > Week 2
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
18Q
01
Consider the following Python code. What will be the output? ``` x, y, z = "", "python", 0 print((x or y) and (z or len(y))) ```
Single correct
EASY
3 marks
26 October 2025
02
Consider the below code. Select the possible output(s) of the given code, assuming any possible values for `x`, `y`, and `z`. ``` if x: print('x') else: if y: if z: print('z') print('y') else: print('none') ```
Multiple correct
MEDIUM
3 marks
26 October 2025
03
An investor decides on an action based on the performance of a stock and the prevailing market trend. The following code accepts two string variables `stock` and `market` as inputs and prints the corresponding action as output. Which of the following statements about the code execution are true? The options are independent of each other. ``` 1 stock = input() 2 market = input() 3 4 if stock == 'rising': 5 if market == 'bull': 6 action = 'buy' 7 else: 8 action = 'hold' 9 10 if stock == 'falling': 11 action = 'sell' 12 13 if stock == 'stable': 14 if market == 'bull': 15 action = 'hold' 16 else: 17 action = 'watch' 18 19 print(action) ```
Multiple correct
MEDIUM
4 marks
23 February 2025
04
Which of the following will output `True`?
Comprehension
MEDIUM
2 marks
23 February 2025
05
Which of the following will output `False`?
Comprehension
MEDIUM
2 marks
23 February 2025
06
Consider the following code snippet where `num` gets an integer number from user input. ``` num = int(input()) if num > 0: num = num + 100 else: num = abs(num - 100) print(num) ``` Choose the correct options regarding the above code.
Multiple correct
MEDIUM
3 marks
27 October 2024
07
Two integers are entered as strings for the following code snippet. For instance, input `"15"` for `number_1` and `"7"` for `number_2`. What will be the output for the specified input? ``` number_1 = int(input()) number_2 = int(input()) if number_1 == number_2: if number_1 % 2 == 0: print(number_1) else: print(number_2) elif number_2 < number_1: print(number_1 // number_2) else: print(number_2 // number_1) ```
Numerical
EASY
3 marks
27 October 2024
08
Consider the following snippet. Select all inputs for which the output is: ``` Luxury range ``` ``` price = float(input()) if price <= 100: print("Affordable range") elif price <= 500: print("Mid-range") elif price <= 1000: print("Higher range") else: print("Luxury range") ```
Multiple correct
EASY
3 marks
07 July 2024
09
What is the output of the following snippet of code? Enter an integer as your answer. ``` x = 15 y = 20 if x != y: result = abs(x - y) else: result = x + y print(result) ```
Numerical
EASY
3 marks
07 July 2024
10
Consider the following snippet: ``` num = float(input()) if num >= 1 and num < 2: print('floor is one') if num >= 2 and num < 3: print('floor is two') if num >= 3 and num < 4: print('floor is three') else: print('floor is four') ``` Select all inputs for which the output is exactly the following line: ``` floor is four ```
Multiple correct
MEDIUM
3 marks
29 October 2023
11
Given integers `x`, `y`, we call `(x, y)` a point. Order matters. That is, `(2, 3)` is a different point from `(3, 2)`. ``` x = int(input()) y = int(input()) label = 'negative' if x >= 0 and x <= 5: if y >= 0 and y <= 5: label = 'positive' print(label) ``` Find the total number of points for which this code will output the value `positive`.
Numerical
MEDIUM
4 marks
29 October 2023
12
Consider the following code snippet. For what values as input, after execution, does the above code snippet not produce any output but runs without any error? ``` x = int(input()) y = int(input()) if x > 5: if y > 15: print("A") ```
Single correct
EASY
2 marks
16 July 2023
13
Consider the following Python code snippet. What will be the output when you run the code? ``` x = 15 y = 20 if x > y: result = x - y elif x < y: result = y - x else: result = x + y print(result) ```
Single correct
EASY
2 marks
16 July 2023
14
Consider the following code snippet. Based on the code, which of the following options is correct? ``` a = 4 b = 7 c = int(input()) if a > b: if b > c: print("A") elif a > c: print("B") else: print("C") else: if b < c: print("D") else: print("E") ```
Single correct
MEDIUM
3 marks
16 July 2023
15
E1 and E2 are Boolean expressions. Consider the following expression: `not(E1 and E2) == (not E1 and not E2)` What can you say about the value of the expression given above?
Single correct
MEDIUM
3 marks
16 October 2022
16
Consider the following code snippet: ``` a, b, c, d = input() print((a + b + c) * int(d)) ``` What will be the output of the code given above for the following input? ``` 1234 ```
Single correct
EASY
3 marks
16 October 2022
17
`A` is a positive integer that represents the age. Consider the following snippet of code: ``` if 0 < A <= 14: print('child') elif 14 < A <= 24: print('youth') elif 24 < A <= 64: print('adult') else: print('senior') ``` Two snippets of code are equivalent if they produce the same output for any given input. Select all snippets of code that are equivalent to the code given above.
Multiple correct
MEDIUM
3 marks
16 October 2022
18
A programmer likes to do certain activities depending on the time of day and the prevailing weather conditions. The code accepts two string variables `weather` and `time` as inputs and prints the corresponding activity as output. Which statements about the code execution are true? The options are independent of each other. ``` weather = input() time = input() if weather == 'sunny': if time == 'morning': activity = 'read' else: activity = 'walk' if weather == 'rainy': activity = 'sleep' if weather == 'cold': if time == 'morning': activity = 'read' else: activity = 'watch' print(activity) ```
Multiple correct
MEDIUM
4 marks
05 June 2022
Showing 18 questions.
Programming in Python > Week 2
All PYQs
Topic-Wise PYQs
Start Weekly Test
Mock tests
Week mock
Topic mock
Subject mock
Type:
All
Difficulty:
All
Year:
All
18Q
01
Consider the following Python code. What will be the output? ``` x, y, z = "", "python", 0 print((x or y) and (z or len(y))) ```
Single correct
EASY
3 marks
26 October 2025
02
Consider the below code. Select the possible output(s) of the given code, assuming any possible values for `x`, `y`, and `z`. ``` if x: print('x') else: if y: if z: print('z') print('y') else: print('none') ```
Multiple correct
MEDIUM
3 marks
26 October 2025
03
An investor decides on an action based on the performance of a stock and the prevailing market trend. The following code accepts two string variables `stock` and `market` as inputs and prints the corresponding action as output. Which of the following statements about the code execution are true? The options are independent of each other. ``` 1 stock = input() 2 market = input() 3 4 if stock == 'rising': 5 if market == 'bull': 6 action = 'buy' 7 else: 8 action = 'hold' 9 10 if stock == 'falling': 11 action = 'sell' 12 13 if stock == 'stable': 14 if market == 'bull': 15 action = 'hold' 16 else: 17 action = 'watch' 18 19 print(action) ```
Multiple correct
MEDIUM
4 marks
23 February 2025
04
Which of the following will output `True`?
Comprehension
MEDIUM
2 marks
23 February 2025
05
Which of the following will output `False`?
Comprehension
MEDIUM
2 marks
23 February 2025
06
Consider the following code snippet where `num` gets an integer number from user input. ``` num = int(input()) if num > 0: num = num + 100 else: num = abs(num - 100) print(num) ``` Choose the correct options regarding the above code.
Multiple correct
MEDIUM
3 marks
27 October 2024
07
Two integers are entered as strings for the following code snippet. For instance, input `"15"` for `number_1` and `"7"` for `number_2`. What will be the output for the specified input? ``` number_1 = int(input()) number_2 = int(input()) if number_1 == number_2: if number_1 % 2 == 0: print(number_1) else: print(number_2) elif number_2 < number_1: print(number_1 // number_2) else: print(number_2 // number_1) ```
Numerical
EASY
3 marks
27 October 2024
08
Consider the following snippet. Select all inputs for which the output is: ``` Luxury range ``` ``` price = float(input()) if price <= 100: print("Affordable range") elif price <= 500: print("Mid-range") elif price <= 1000: print("Higher range") else: print("Luxury range") ```
Multiple correct
EASY
3 marks
07 July 2024
09
What is the output of the following snippet of code? Enter an integer as your answer. ``` x = 15 y = 20 if x != y: result = abs(x - y) else: result = x + y print(result) ```
Numerical
EASY
3 marks
07 July 2024
10
Consider the following snippet: ``` num = float(input()) if num >= 1 and num < 2: print('floor is one') if num >= 2 and num < 3: print('floor is two') if num >= 3 and num < 4: print('floor is three') else: print('floor is four') ``` Select all inputs for which the output is exactly the following line: ``` floor is four ```
Multiple correct
MEDIUM
3 marks
29 October 2023
11
Given integers `x`, `y`, we call `(x, y)` a point. Order matters. That is, `(2, 3)` is a different point from `(3, 2)`. ``` x = int(input()) y = int(input()) label = 'negative' if x >= 0 and x <= 5: if y >= 0 and y <= 5: label = 'positive' print(label) ``` Find the total number of points for which this code will output the value `positive`.
Numerical
MEDIUM
4 marks
29 October 2023
12
Consider the following code snippet. For what values as input, after execution, does the above code snippet not produce any output but runs without any error? ``` x = int(input()) y = int(input()) if x > 5: if y > 15: print("A") ```
Single correct
EASY
2 marks
16 July 2023
13
Consider the following Python code snippet. What will be the output when you run the code? ``` x = 15 y = 20 if x > y: result = x - y elif x < y: result = y - x else: result = x + y print(result) ```
Single correct
EASY
2 marks
16 July 2023
14
Consider the following code snippet. Based on the code, which of the following options is correct? ``` a = 4 b = 7 c = int(input()) if a > b: if b > c: print("A") elif a > c: print("B") else: print("C") else: if b < c: print("D") else: print("E") ```
Single correct
MEDIUM
3 marks
16 July 2023
15
E1 and E2 are Boolean expressions. Consider the following expression: `not(E1 and E2) == (not E1 and not E2)` What can you say about the value of the expression given above?
Single correct
MEDIUM
3 marks
16 October 2022
16
Consider the following code snippet: ``` a, b, c, d = input() print((a + b + c) * int(d)) ``` What will be the output of the code given above for the following input? ``` 1234 ```
Single correct
EASY
3 marks
16 October 2022
17
`A` is a positive integer that represents the age. Consider the following snippet of code: ``` if 0 < A <= 14: print('child') elif 14 < A <= 24: print('youth') elif 24 < A <= 64: print('adult') else: print('senior') ``` Two snippets of code are equivalent if they produce the same output for any given input. Select all snippets of code that are equivalent to the code given above.
Multiple correct
MEDIUM
3 marks
16 October 2022
18
A programmer likes to do certain activities depending on the time of day and the prevailing weather conditions. The code accepts two string variables `weather` and `time` as inputs and prints the corresponding activity as output. Which statements about the code execution are true? The options are independent of each other. ``` weather = input() time = input() if weather == 'sunny': if time == 'morning': activity = 'read' else: activity = 'walk' if weather == 'rainy': activity = 'sleep' if weather == 'cold': if time == 'morning': activity = 'read' else: activity = 'watch' print(activity) ```
Multiple correct
MEDIUM
4 marks
05 June 2022
Showing 18 questions.