Quiz Space

Python OPPE 1: September 2024, Set 3 (September 2024 term)

Question 1

+10 marksProgramming

Write a function div_by_exactly_one that takes three integers num, a, and b. The function should return True if num is divisible by exactly one of the numbers a or b, and False otherwise.

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.

Examples:

  • num=20, a=5, b=6 --> True (20 is divisible by 5 only)
  • num=20, a=5, b=10 --> False (20 is divisible by both 5 and 10)
  • num=20, a=6, b=10 --> True (20 is divisible by 10 only)
  • num=20, a=6, b=7 --> False (20 is not divisible by either 6 or 7)

Your task

Implement this function:

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

Example

Input

20
5
6

Output

True

Question 2

+10 marksProgramming

Convert a date string from the format mm-dd-yy to yy-dd-mm.

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

Input: "12-25-21"
Output: "21-25-12"

Your task

Implement this function:

def mm_dd_yy_to_yy_dd_mm(date: 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: date.

Example

Input

'12-25-21'

Output

'21-25-12'

Question 3

+10 marksProgramming

Write a function increment_value_with_max_limit that increments the value for a specified key in a dictionary by a given increment value (inc). However, the value should not exceed a specified maximum limit (limit).

Assume the dictionary values are integers. If the resulting value after incrementing is greater than the limit, it should be capped at the limit.

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

>>> d = {"x": 5, "y": 3, "z": 5}
>>> key, inc, limit = "y", 5, 5
>>> increment_value_with_max_limit(d, key, inc, limit)
>>> d
{"x": 5, "y": 5, "z": 5}   # 3+5=8 but max limit is 5

>>> increment_value_with_max_limit(d, "z", 5, 11)
>>> d
{"x": 5, "y": 5, "z": 10}  # 5+5=10 less than limit

>>> increment_value_with_max_limit(d, "x", 5, 4)
>>> d
{"x": 4, "y": 5, "z": 10}  # capped at the limit 4

Your task

Implement this function:

def increment_value_with_max_limit(d: dict, key: str, inc: int, limit: 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: d, key, inc, limit.

Example

Input

{'x': 5, 'y': 3, 'z': 5}
'y'
5
5

Output

{'x': 5, 'y': 5, 'z': 5}

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

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

Other sets that day

Same OPPE 1, other subjects

More Python