Quiz Space

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

Question 1

+5 marksProgramming

Given two integers, find the absolute difference between their sum and the sum of their squares.

Eg.
a, b = 2,3
sum is 5
sum of squares is 13
absolute difference is 8

Args:

    a - int : The first integer.
    b - int : The second integer.

Returns:
int: absolute difference between the sum and the sum of squares

Your task

Implement this function:

def abs_diff_between_sum_and_sum_of_squares(a:int, b: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: a, b.

Example

Input

2
3

Output

8

Question 2

+5 marksProgramming

Given an odd-length string, swap the parts before and after the middle three characters, while keeping the middle three characters in place.

Assume the string has at least 5 characters.

Examples

    "firstabclast1" -> "last1abcfirst"
    "abcdefghi" -> "ghidefabc"

Args:
s (str): The input string of odd length.

Returns:
str: The modified string with the parts swapped.

Your task

Implement this function:

def swap_except_middle_three(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

'abcdefghi'

Output

'ghidefabc'

Question 3

+5 marksProgramming

Given three lists of same length, interleave them together and return the interleaved list.

Example

    list1 = [1, 2, 3]
    list2 = ['a', 'b', 'c']
    list3 = [(1,1),(2,2),(3,3)]
    output = [1, 'a', (1,1), 2, 'b', (2,2), 3, 'c', (3,3)]

Args:

    list1 (list): The first list.
    list2 (list): The second list.
    list3 (list): The third list.

Returns:
list: A list containing interleaved elements from all three lists.

Your task

Implement this function:

def interleave_lists(list1, list2, list3):

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: list1, list2, list3.

Example

Input

[1, 2, 3]
['a', 'b', 'c']
[(1, 1), (2, 2), (3, 3)]

Output

[1, 'a', (1, 1), 2, 'b', (2, 2), 3, 'c', (3, 3)]

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

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

Other sets that day

More Python