Quiz Space

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

Question 1

+10 marksProgramming

Write a function is_three_digit_and_digit_sum_divisible_by_k(n, k) that returns True if n is a three-digit number (from 100 to 999) and the sum of its digits is divisible by k. In every other case it returns False.

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

is_three_digit_and_digit_sum_divisible_by_k(145, 5) -> True
is_three_digit_and_digit_sum_divisible_by_k(123, 5) -> False

Your task

Implement this function:

def is_three_digit_and_digit_sum_divisible_by_k(n: int, k: int) -> bool:

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, k.

Example

Input

145
5

Output

True

Question 2

+10 marksProgramming

The string s has at least 4 characters. Write a function remove_second_and_second_last(s) that returns s without its second character and without its second-last character.

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

remove_second_and_second_last("abcdef") -> 'acdf'
remove_second_and_second_last("abcd") -> 'ad'

Your task

Implement this function:

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

'acdf'

Question 3

+10 marksProgramming

The keys of the dictionary d are integers, and k1 and k2 are two different keys of d whose values are numbers. Write a function add_average_key_diff(d, k1, k2) that adds a new entry to d. Its key is the average of k1 and k2 rounded with round(), and its value is the absolute difference of the values of k1 and k2. The function changes d 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

add_average_key_diff({2: 10, 8: 30}, 2, 8) -> {2: 10, 8: 30, 5: 20}
add_average_key_diff({1: 5, 3: 2, 10: 7}, 1, 3) -> {1: 5, 3: 2, 10: 7, 2: 3}

Your task

Implement this function:

def add_average_key_diff(d: dict, k1, k2) -> 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: d, k1, k2.

Example

Input

{2: 10, 8: 30}
2
8

Output

{2: 10, 8: 30, 5: 20}

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

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

Other sets that day

Same OPPE 2, other subjects

More Python