Quiz Space

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

Question 1

+10 marksProgramming

Write a function extract_border_elements(arr) that returns a list with the first and the last element of arr. If arr has only one element, the result has just that element. If arr is empty, the result is an empty list.

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_border_elements([1, 2, 3, 4]) -> [1, 4]
extract_border_elements([5]) -> [5]

Your task

Implement this function:

def extract_border_elements(arr: 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: arr.

Example

Input

[1, 2, 3, 4]

Output

[1, 4]

Question 2

+10 marksProgramming

The strings time1 and time2 are times of one day in the 24 hour format "HH:MM". Write a function absolute_time_difference(time1, time2) that returns the difference between them, whichever is earlier, as a string in the format "HH:MM", with two digits for the hours and two digits for the minutes.

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

absolute_time_difference("14:30", "06:45") -> '07:45'
absolute_time_difference("02:30", "03:10") -> '00:40'

Your task

Implement this function:

def absolute_time_difference(time1: str, time2: str) -> 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: time1, time2.

Example

Input

"14:30"
"06:45"

Output

'07:45'

Question 3

+10 marksProgramming

The dictionary accounts maps account numbers to their balances. Write a function transfer_amount(accounts, sender, recipient, amount) that moves amount from the account sender to the account recipient. The transfer is made only if both accounts are in accounts, amount is not negative, and the balance of sender is at least amount. Otherwise accounts is left as it is. The function changes accounts itself and returns nothing.

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

transfer_amount({"12345": 500, "67890": 1000, "98764": 1500}, "12345", "67890", 1000) -> {'12345': 500, '67890': 1000, '98764': 1500}
transfer_amount({"12345": 500, "67890": 1000, "98764": 1500}, "12345", "67890", 400) -> {'12345': 100, '67890': 1400, '98764': 1500}

Your task

Implement this function:

def transfer_amount(accounts: dict, sender: str, recipient: str, amount: int) -> None:

Write the function only — the arguments are read for you and the argument you change is printed automatically.

Arguments arrive as one Python literal per line, in this order: accounts, sender, recipient, amount.

Example

Input

{"12345": 500, "67890": 1000, "98764": 1500}
"12345"
"67890"
1000

Output

{'12345': 500, '67890': 1000, '98764': 1500}

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 3 paper

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

Other sets that day

More Python