Quiz Space

Python OPPE 1: September 2025, Set 2 (September 2025 term)

Question 1

+10 marksProgramming

Write a function extract_middle_elements(lst:list) that takes a list of integers and returns a new list containing only the middle element if the list has an odd length, or the two middle elements if the list has an even length.

NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition.

Examples

extract_middle_elements([7, 8, 9, 10, 11, 12, 13]) -> [10]
Explanation: The list has an odd length (7), so the middle element is 10.
extract_middle_elements([3, 6, 9, 12, 15, 18]) -> [9, 12]
Explanation: The list has an even length (6), so the two middle elements are 9 and 12.

Your task

Implement this function:

def extract_middle_elements(lst:list):

Write the function only — the arguments are read for you and the return value is printed automatically.

Arguments arrive as one Python literal per line, in this order: lst.

Example

Input

[7, 8, 9, 10, 11, 12, 13]

Output

[10]

Question 2

+10 marksProgramming

Write a function get_first_last_chars_sorted(t) that takes a tuple of strings (with at least two strings) as input and returns a new string formed by:

taking the first character of the first string, and the last character of the last string,

Then, return these two characters arranged in alphabetical order.
(Assume all strings are in lowercase.)

Hint: Alphebetical order can be determined by comparing two chars using comparision operators.

NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition.

Examples

get_first_last_chars_sorted(("apple", "banana", "cherry")) -> "ay" First char of "apple" -> 'a', last char of "cherry" -> 'y'
Sorted alphabetically -> "ay"
get_first_last_chars_sorted(("moon", "sun")) -> "mn"
First char of "moon" -> 'm', last char of "sun" -> 'n'
Sorted alphabetically -> "mn"
get_first_last_chars_sorted(("land", "cab")) -> "bl"
First char of "land" -> 'l', last char of "cab" -> 'b'
Sorted alphabetically -> "bl"

Your task

Implement this function:

def get_first_last_chars_sorted(t: tuple) -> str:

Write the function only — the arguments are read for you and the return value is printed automatically.

Arguments arrive as one Python literal per line, in this order: t.

Example

Input

("apple", "banana", "cherry")

Output

'ay'

Question 3

+10 marksProgramming

Given two strings, bread and filling, split bread into two equal halves and insert the filling in between them to form a new word.\

Assume the string bread will be of even length.

NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition.

Example

>>> bread = "topbun"
>>> filling = "butter"
>>> word_sandwich(bread,filling)
'topbutterbun'

Your task

Implement this function:

def word_sandwich(bread, filling):

Write the function only — the arguments are read for you and the return value is printed automatically.

Arguments arrive as one Python literal per line, in this order: bread, filling.

Example

Input

"topbun"
"butter"

Output

'topbutterbun'

4 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the Python OPPE 1 Sept 2025 Set 2 paper

The IIT Madras BS Programming in Python (Python) OPPE 1 paper sat on Sept 2025, in the September 2025 term (T3 2025), set 2: 7 questions for 100 marks in 180 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeaturePython OPPE 1 Sept 2025 Set 2 at a glance
TermSeptember 2025 term (T3 2025)
SubjectProgramming in Python
Course codeBSCS1002
Questions7
Marks100
Duration180 min
Programming7
Official paperOPPE 1, Sep 2025 Set 2
Negative markingNo negative marking.
Updated

Other sets that day

Same OPPE 1, other subjects

More Python