Quiz Space

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

Question 1

+10 marksProgramming

Write a function is_decreasing_number(n: int) -> bool that checks if a given 4-digit number is decreasing, meaning each digit is strictly less than the digit before it (from left to right).

The function should return True if the number meets the criteria and False otherwise.

Constraints

The input number will be a 4-digit number, which means it will be in the range of 1000 to 9999.

Example

>>> is_decreasing_number(4321)
True
>>> is_decreasing_number(4312)
False
>>> is_decreasing_number(9876)
True
>>> is_decreasing_number(1111)
False
>>> is_decreasing_number(3210)
True

Your task

Implement this function:

def is_decreasing_number(n: 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.

Example

Input

4321

Output

True

Question 2

+10 marksProgramming

Write a function solve_for_x(equation: str) -> float that takes a string representing a linear equation in the form ax+b=c or ax-b=c, where a, b, and c are integers. The function should return the value of x as a float.

The equation will always follow the correct format, which is:

a and b are integer coefficients (they can be positive or negative) and are optional. x is the variable will always be there before the =.
The equality sign and c will always present be present.
If their is no coefficient for x it is assumed to be 1.
The equation might have spaces inbetween or in the end, which have to be ignored.

Hint: Think of x and = as separators.

Example

>>> solve_for_x("2x +3= 11")
4.0
>>> solve_for_x("5x -2 = 13")
3.0
>>> solve_for_x("-3x + 10=1")
3.0
>>> solve_for_x("x + 2 = 5")
3.0
>>> solve_for_x("2x=6")
3.0

Your task

Implement this function:

def solve_for_x(equation: str) -> float:

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: equation.

Example

Input

"2x +3= 11"

Output

4.0

Question 3

+10 marksProgramming

Write a function divide_into_almost_equal_parts(n: int, k: int) -> list that takes two integers, n and k, and creates a list of size k where the elements are approximately equal and sum up to n. The list should contain larger numbers towards the beginning.

The larger numbers should be prioritized for the earlier parts of the list, and you should ensure that the sum of the list matches n.

Constraints

The integers n (total) and k (parts) are both positive integers. The output list will always be of length k.

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

>>> divide_into_almost_equal_parts(5, 3)
[2, 2, 1]
>>> divide_into_almost_equal_parts(16, 3)
[6, 5, 5]
>>> divide_into_almost_equal_parts(12, 4)
[3, 3, 3, 3]
>>> divide_into_almost_equal_parts(10, 3)
[4, 3, 3]

Your task

Implement this function:

def divide_into_almost_equal_parts(n: int, k: int) -> list:

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

5
3

Output

[2, 2, 1]

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

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

Other sets that day

Same OPPE 1, other subjects

More Python