Quiz Space

Programming in Python OPPE 2: January 2025, Set 2 (January 2025 term)

Question 1

+10 marksProgramming

Write a function extract_middle_elements(lst) that takes a non-empty list and returns a list with its middle element, if the length of lst is odd, or with its two middle elements, in their order, if the length is even.

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

extract_middle_elements([7, 8, 9, 10, 11, 12, 13]) -> [10]
extract_middle_elements([3, 6, 9, 12, 15, 18]) -> [9, 12]

Your task

Implement this function:

def extract_middle_elements(lst: list) -> 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

The string sentence has exactly three words, separated by single spaces. The tuple order is a permutation of 0, 1, 2. Write a function shuffle_sentence(sentence, order) that returns the sentence with its words put in the order given by order: the first word of the result is the word of sentence whose index is order[0], and so on.

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

shuffle_sentence("apple banana orange", (0, 2, 1)) -> 'apple orange banana'
shuffle_sentence("cat dog mouse", (2, 1, 0)) -> 'mouse dog cat'

Your task

Implement this function:

def shuffle_sentence(sentence: str, order: 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: sentence, order.

Example

Input

"apple banana orange"
(0, 2, 1)

Output

'apple orange banana'

Question 3

+10 marksProgramming

Write a function same_sign(a, b) that returns True if both numbers are positive, or both are negative, or both are zero. Otherwise it returns False.

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

same_sign(10, 20) -> True
same_sign(-5, -15) -> True

Your task

Implement this function:

def same_sign(a, b) -> bool:

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: a, b.

Example

Input

10
20

Output

True

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 2 Jan 2025 Set 2 paper

The IIT Madras BS Programming in Python (Python) OPPE 2 paper sat on Jan 2025, in the January 2025 term (T1 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 2 Jan 2025 Set 2 at a glance
TermJanuary 2025 term (T1 2025)
SubjectProgramming in Python
Course codeBSCS1002
Questions7
Marks100
Duration180 min
Programming7
Official paperOPPE 2, Jan 2025 Set 2
Negative markingNo negative marking.
Updated

Other sets that day

More Python