Quiz Space

Programming in Python OPPE 1: May 2025, Set 4 (May 2025 term)

Question 1

+10 marksProgramming

Write a function double_ends(l) that takes a list l (with at least two elements) and returns a new list where the first and last elements of l are duplicated at the beginning and end of the list, respectively.

The new list should have:

The first element of the original list inserted once at the beginning The last element of the original list inserted once at the end

You must not modify the original list.

Constraints

The input list will contain at least two elements
The list can contain elements of any type (integers, strings, etc.)

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

>>> double_ends([10, 20, 30])
[10, 10, 20, 30, 30]
>>> double_ends(['a', 'b', 'c'])
['a', 'a', 'b', 'c', 'c']
>>> double_ends([1, 2])
[1, 1, 2, 2]
>>> double_ends([5, 6, 7, 8])
[5, 5, 6, 7, 8, 8]

Your task

Implement this function:

def double_ends(l: 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: l.

Example

Input

[10, 20, 30]

Output

[10, 10, 20, 30, 30]

Question 2

+10 marksProgramming

Write a function extract_email_username that takes an email address string of the form "[email protected]" and returns just the username part — that is, everything before the @ symbol.

Constraints

The input will always be a valid email address containing exactly one @ symbol. The username can contain letters, numbers, and symbols like dots or underscores. The domain part is irrelevant and should not be returned.

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_email_username("[email protected]")
"ananya.sharma"
>>> extract_email_username("[email protected]")
"rahul123"
>>> extract_email_username("[email protected]")
"priya_r"
>>> extract_email_username("[email protected]")
"v.kumar"

Your task

Implement this function:

def extract_email_username(email: 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: email.

Example

Input

"[email protected]"

Output

'ananya.sharma'

Question 3

+10 marksProgramming

Write a function shuffle_digits(num) that takes a 4-digit positive integer and shuffles the digits in the order 2413. That is

The 2nd digit from left becomes the 1st
The 4th digit from left becomes the 2nd
The 1st digit from left becomes the 3rd
The 3rd digit from left becomes the 4th

Example

>>> shuffle_digits(1234)
2413
>>> shuffle_digits(2413)
4321
>>> shuffle_digits(4321)
3142
>>> shuffle_digits(3142)
1234

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.

Your task

Implement this function:

def shuffle_digits(num: int) -> int:

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: num.

Example

Input

1234

Output

2413

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 May 2025 Set 4 paper

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

Other sets that day

Same OPPE 1, other subjects

More Python