Quiz Space

Programming in Python OPPE 1: May 2024, Set 3 (May 2024 term)

Question 1

+5 marksProgramming

Implement the function according to the docstring.

Square the given integer and clip the result to threshold (clipping means if the value x goes greater than the threshold, keep it at threshold).

Arguments:

  • x: int - the input number
  • threshold: int - the threshold value

Return:

  • int - squared and clipped result

Your task

Implement this function:

def square_and_clip(x: int, threshold: 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: x, threshold.

Example

Input

3
5

Output

5

Question 2

+5 marksProgramming

Implement the function according to the docstring.

Given an even-length string of any case, create a string with the first half in lowercase and the second half in uppercase.

Arguments:

  • s: str - the input string

Return:

  • str - the modified string

Your task

Implement this function:

def lowercase_first_half_and_uppercase_second_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

'HelloWorld'

Output

'helloWORLD'

Question 3

+5 marksProgramming

Implement the function according to the docstring.

Given an odd-length list, insert the middle element to both ends of the list.

Modify the input list and do not return a new list.

Arguments:

  • l: list - the input list

Return:

  • None - the input list is modified inside the function.

Your task

Implement this function:

def add_the_middle_element_to_both_ends(l: list) -> None:

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

[1, 2, 3]

Output

[2, 1, 2, 3, 2]

6 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 2024 Set 3 paper

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

Other sets that day

More Python