Quiz Space

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

Question 1

+10 marksProgramming

Write a function is_positive_odd_or_negative_even that checks if an integer is either a positive odd number or a negative even number. Return True if the number meets one of these conditions; otherwise, 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 cases

  • 0 --> False (neither positive nor negative)
  • 3 --> True (positive odd)
  • -4 --> True (negative even)
  • 4 --> False (positive but even)
  • -3 --> False (negative but odd)

Your task

Implement this function:

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

0

Output

False

Question 2

+10 marksProgramming

Write a function within_and_has_double_quotes that checks if a given string starts and ends with double quotes, and if there are double quotes inside the string (excluding the first and last characters). Return True if both conditions are met, 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.

Example cases

  • "abcd"efgh" --> True (starts and ends with double quotes, and has double quotes inside)
  • 'abcd"efgh"' --> False (does not start with double quotes)
  • "'abcd'efgh'" --> False (uses single quotes)
  • "abcdefgh" --> False (no double quotes inside the quotes)

Your task

Implement this function:

def within_and_has_double_quotes(s: str) -> 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: s.

Example

Input

'"abcd"efgh"'

Output

True

Question 3

+10 marksProgramming

Given a tuple t of odd length, and a positive integer n, replace the middle element with n copies of itself.

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

For t = (1, 2, 3, 4, 5) and n = 5, the result should be (1, 2, 3, 3, 3, 3, 3, 4, 5).

For t = (1, 2, 3) and n = 4, the result should be (1, 2, 2, 2, 2, 3).

Your task

Implement this function:

def replace_middle_with_n_times_middle(t: tuple, n: int) -> 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, n.

Example

Input

(1, 2, 3, 4, 5)
5

Output

(1, 2, 3, 3, 3, 3, 3, 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 Sept 2024 Set 2 paper

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

Other sets that day

Same OPPE 1, other subjects

More Python