Quiz Space

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

Question 1

+10 marksProgramming

Write a function product_of_sum_and_abs_diff_of_digits(num) that takes a two-digit number (it may be negative, then ignore the sign) and returns the product of the sum of its two digits and the absolute difference of its two digits.

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

product_of_sum_and_abs_diff_of_digits(54) -> 9
product_of_sum_and_abs_diff_of_digits(38) -> 55

Your task

Implement this function:

def product_of_sum_and_abs_diff_of_digits(num: 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: num.

Example

Input

54

Output

9

Question 2

+10 marksProgramming

Write a function is_divisible_by_last_two_digits(num) that returns True if the positive integer num is divisible by each of its last two digits (the units digit and the tens digit). If either of these two digits is 0, return 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_divisible_by_last_two_digits(1236) -> True
is_divisible_by_last_two_digits(345) -> False

Your task

Implement this function:

def is_divisible_by_last_two_digits(num: 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.

Example

Input

1236

Output

True

Question 3

+10 marksProgramming

The values of the dictionary d are non-empty strings. Write a function swap_last_chars_of_values(d, k1, k2) that swaps the last character of the value at key k1 with the last character of the value at key 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

swap_last_chars_of_values({"first": "apple", "second": "mango", "third": "banana"}, "first", "second") -> {'first': 'applo', 'second': 'mange', 'third': 'banana'}
swap_last_chars_of_values({"key1": "hello", "key2": "world"}, "key1", "key2") -> {'key1': 'helld', 'key2': 'worlo'}

Your task

Implement this function:

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

{"first": "apple", "second": "mango", "third": "banana"}
"first"
"second"

Output

{'first': 'applo', 'second': 'mange', 'third': 'banana'}

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

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

Other sets that day

More Python