Quiz Space

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

Question 1

+10 marksProgramming

Write a function point_position_relative_to_line(a, b, c, x, y) -> int that determines the position of a point (x, y) with respect to a line described by the equation ax + by + c = 0.

The function should return:

+1 if the point is above the line
-1 if the point is below the line
0 if the point is on the line

Note

A point (x, y) is considered on the line if substituting x and y into the equation results in 0. A point is above the line if the value of ax + by + c > 0 and below the line if ax + by + c < 0.

Example

>>> point_position_relative_to_line(1, -1, 0, 2, 1)
>>> point_position_relative_to_line(-1, -1, -1, 0, 0)
-1
>>> point_position_relative_to_line(2, -1, -4, 2, 0)

Your task

Implement this function:

def point_position_relative_to_line(a, b, c, x, y) -> 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, c, x, y.

Example

Input

1
-1
0
2
1

Output

1

Question 2

+10 marksProgramming

Write a function expand_sum_of_products(expr: str) -> str that takes a string representation of a product of sum of two terms in the form "(a+b)(c+d)", and expands it into the sum of products in the form "ac + ad + bc + bd". The output should be a properly formatted string of the expanded form.

The input can have spaces in between the symbols and operators. The spacing and ordering of the terms should be exacty as given in the format.

There will be always + sign between the values in a term.

Example

>>> expand_sum_of_products("(a+b)(c+d)")
"a*c + a*d + b*c + b*d"
>>> expand_sum_of_products("(x+y)(z+w)")
"x*z + x*w + y*z + y*w"
>>> expand_sum_of_products("(1+5)(10+12)")
"1*10 + 1*12 + 5*10 + 5*12"

Your task

Implement this function:

def expand_sum_of_products(expr: 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: expr.

Example

Input

"(a+b)(c+d)"

Output

'a*c + a*d + b*c + b*d'

Question 3

+10 marksProgramming

Write a function repeat_second_half(t) that takes a tuple t and returns a new tuple where the second half of the original tuple is repeated after the first half. If the tuple has an odd number of elements, the middle element should be included in the first half.

Constraints

The input tuple will contain at least two elements.
The elements in the tuple can be of any type (integers, strings, etc.).

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

>>> repeat_second_half((1, 2, 3, 4, 5))
(1, 2, 3, 4, 5, 4, 5)
>>> repeat_second_half((10, 20, 30, 40))
(10, 20, 30, 40, 30, 40)
>>> repeat_second_half(('a', 'b', 'c', 'd', 'e', 'f'))
('a', 'b', 'c', 'd', 'e', 'f', 'd', 'e', 'f')
>>> repeat_second_half((1, 2, 3))
(1, 2, 3, 3)

Your task

Implement this function:

def repeat_second_half(t: tuple) -> tuple:

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

Example

Input

(1, 2, 3, 4, 5)

Output

(1, 2, 3, 4, 5, 4, 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 May 2025 Set 5 paper

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

Other sets that day

Same OPPE 1, other subjects

More Python