Quiz Space

Programming in Python · End Term · 21 Dec 2025 · September 2025 term

Question 17: Consider the following snippet: def ProcedureOne(M): n =…

Question 17

+2 marksOne correct option

Consider the following snippet: def ProcedureOne(M): n = len(M) for i in range(n): temp = M[i][i] M[i][i] = M[i][-i - 1] M[i][-i - 1] = temp return M def ProcedureTwo(M): p = 1 n = len(M) for i in range(n): p *= M[i][i] return p M = [[2, 4, 6], [8, 10, 12], [14, 16, 18]] P = ProcedureOne(M) print(P) print(ProcedureTwo(P)) Based on the above code answer the subsequent questions.

What is the first line of output?

  1. A

    [[6, 4, 2], [8, 10, 12], [18, 16, 14]]

  2. B

    [[2, 4, 6], [8, 10, 12], [14, 16, 18]]

  3. C

    [[14, 16, 18], [8, 10, 12], [2, 4, 6]]

  4. D

    [[2, 6, 4], [8, 12, 10], [14, 18, 16]]

Show answer

Correct answer

  • A

    [[6, 4, 2], [8, 10, 12], [18, 16, 14]]

Question 17 of 20 in the IIT Madras BS Programming in Python (Python) End Term paper sat on 21 Dec 2025, in the September 2025 term (Intro to Python 18 Dec 25). It carries 2 marks.

More questions from this paper

  1. Q1Consider the following functions: def p(n): if n < 10: return 1 return 1 + p(n // 10) def q(n): if n < 10: return n ret…
  2. Q2Consider the following code snippet that writes student details to a CSV file named "employees.csv": def save_data(data…
  3. Q3What will be the output of the following Python code? string1 = 'database' string2 = 'baseball' L = [] for i in range(l…
  4. Q4What is the output of the following snippet of code? sentence = 'python,is,fun,and,learning,python,is,great' D = dict()…
  5. Q5If n is a positive integer, what does the following snippet compute? Q = [x for x in range(1, 3 n + 1) if x % 3 == 0] p…
  6. Q6Consider the following snippets of code: Code-1 T = (4, 5, 6) T[0] = 10 Code-2 S = set() S.insert(2) Code-3 L = [] L.ap…
  7. Q7employees is a list of tuples. Each tuple is of the form (name, salary) . Select all snippets of code that create a lis…
  8. Q8Consider the following snippet: f = open('employees.csv', 'r') D = dict() for line in f: name, department, salary = lin…
  9. Q9Consider the following snippet of code: def analyze_string(t, k): freq = {} for ch in t: freq[ch] = freq.get(ch, 0) + 1…
  10. Q10What is the output of the following snippet of code? def g(x, y): if x == 1: return 0 return 1 + g(x // y, y) print(g(1…
  11. Q11What is the output of the following snippet of code? total = 0 errors = 0 for s in ['5', '2.5', '7', '8']: try: n = int…
  12. Q12What is the output of the following snippet of code? total = 0 num = 10 while num <= 20: count = 0 for i in range(1, nu…
  13. Q13Consider the following snippet of code: L = [2, 3, 4] S = [] T = 0 i = 0 while i < len(L): S += L[:i] + L[i:] for j in …
  14. Q14What is the output of the following snippet of code? def doSomething(x, y): if x < y: return 0 return 1 + doSomething(x…
  15. Q15You are inside the lift of a building. There are 8 levels in the building: [−3,−2,−1,0,1,2,3,4] The number 0 is the gro…
  16. Q16You are inside the lift of a building. There are 8 levels in the building: [−3,−2,−1,0,1,2,3,4] The number 0 is the gro…
  17. Q18Consider the following snippet: def ProcedureOne(M): n = len(M) for i in range(n): temp = M[i][i] M[i][i] = M[i][-i - 1…
  18. Q19You are inside the lift of a building. There are 8 levels in the building: [−3,−2,−1,0,1,2,3,4] The number 0 is the gro…
  19. Q20Consider the following snippet: def ProcedureOne(M): n = len(M) for i in range(n): temp = M[i][i] M[i][i] = M[i][-i - 1…