Quiz Space

Programming in Python OPPE 1: May 2026, Set 2 (May 2026 term)

Question 1

+10 marksProgramming

Write a function reverse_first_half(s) that returns a new string in which the first half of s is reversed and the second half is left as it is. The first half is the first len(s) // 2 characters; so when s has an odd length, its middle character belongs to the second half.

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

reverse_first_half("abcdef") -> 'cbadef'
reverse_first_half("python") -> 'typhon'

Your task

Implement this function:

def reverse_first_half(s: 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: s.

Example

Input

"abcdef"

Output

'cbadef'

Question 2

+10 marksProgramming

passenger is a dictionary with the keys "age" and "has_id" (True or False). Write a function train_ticket(passenger, available_seats) that checks these rules in this order and returns the answer of the first rule that applies:

  1. If the passenger has no ID, return "ID Required".
  2. If available_seats is 0, return "Waiting List".
  3. If the passenger is 60 years old or older, return "Priority Booking".
  4. Otherwise, return "Ticket Confirmed".

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

train_ticket({"age": 65, "has_id": True}, 5) -> 'Priority Booking'
train_ticket({"age": 30, "has_id": False}, 5) -> 'ID Required'

Your task

Implement this function:

def train_ticket(passenger: dict, available_seats: int) -> 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: passenger, available_seats.

Example

Input

{"age": 65, "has_id": True}
5

Output

'Priority Booking'

Question 3

+10 marksProgramming

Write a function double_if_even_else_square(n) that returns n multiplied by 2 if n is even, and the square of n if n is odd.

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_if_even_else_square(8) -> 16
double_if_even_else_square(9) -> 81

Your task

Implement this function:

def double_if_even_else_square(n: 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: n.

Example

Input

8

Output

16

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 2026 Set 2 paper

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

Other sets that day

Same OPPE 1, other subjects

More Python