Quiz Space

Programming in Python · End Term · 31 Aug 2025 · May 2025 term · Set QDF3

Question 4: Consider the below output.\ 1 4 7\ 2 5 8\ 3 6 9\ Select t…

Question 4

+3 marksOne correct option

Consider the below output.
1 4 7
2 5 8
3 6 9
Select the code snippet that will generate the above output.

  1. A

    matrix = [[i + (j+1)*3 for i in range(3)] for j in range(3)]
    for row in matrix:
    print(*row)

  2. B

    matrix = [[(i+1) + j*3 for i in range(3)] for j in range(3)]
    for row in matrix:
    print(*row)

  3. C

    matrix = [[(j+1) + i*3 for j in range(3)] for i in range(3)]
    for row in matrix:
    print(*row)

  4. D

    matrix = [[(i+1) + j*3 for j in range(3)] for i in range(3)]
    for row in matrix:
    print(*row)

Show answer

Correct answer

  • D

    matrix = [[(i+1) + j*3 for j in range(3)] for i in range(3)]
    for row in matrix:
    print(*row)

Question 4 of 18 in the IIT Madras BS Programming in Python (Python) End Term paper sat on 31 Aug 2025, in the May 2025 term (IIT M FOUNDATION AN EXAM QDF3 31 Aug 2025). It carries 3 marks.

More questions from this paper

  1. Q1Given the following code snippet, what will be the output?\ if None:\ print("None is True")\ elif 0:\ print("0 is True"…
  2. Q2Consider the below code snippet.\ def updated_val(d, key, val):\ if key in d:\ d[key] += val\ else:\ d[key] = val\ retu…
  3. Q3Given the following code snippet, what will be the output?\ a = (1, 2)\ b = (3, 4)\ c = ((5, 6),)\ d = a + b + c\ e = d…
  4. Q5Given the following code snippet, what will be the output?\ def update_records(records, updates):\ for key, value in up…
  5. Q6Given the following code snippet, what will be the output?\ def get_square(items, i):\ return items[i]2\ def safe_get_s…
  6. Q7Consider the following snippet of code:\ t1 = (1, 2, 3)\ t2 = (4, 5, 6)\ t3 = t1 + t2\ t4 = (t1, t2)\ print(t3[2:5])\ p…
  7. Q8Consider the following snippet of code:\ filename = "test.txt"\ with open(filename, "w") as f:\ f.write("\n".join((f"Li…
  8. Q9Consider the following snippet of code:\ class Shape:\ def init(self):\ pass\ def area(self):\ return "Area not defined…
  9. Q10Consider the below python code.\ lst = []\ for i in range(5):\ lst.append(i)\ lst.append(i10)\ lst[1:4] = [100]\ print(…
  10. Q11Consider the below python code.\ def process_array(arr):\ total = 0\ for i, row in enumerate(arr):\ total += row[i]\ re…
  11. Q12Consider the below python code.\ def procedure(child_dict, i):\ if i not in child_dict.keys():\ return 1\ ans = 1\ for …
  12. Q13Consider the below python code.\ class A:\ def init(self):\ self.value = 5\ def add(self, num):\ self.value += num\ ret…
  13. Q14On executing the given code, how many number of lines will be there in the file example_file.txt ?
  14. Q15What will be printed if we call random_access_read(filename, seek_pos) immediately after running the given code?
  15. Q16What will be the value of the following expression after running the given code snippet?\ sorted(result["cat_1"] \& res…
  16. Q17What will be the value of the following expression after running the given code snippet?\ len(result["cat_1"] | result[…
  17. Q18If result = categorize_numbers([1, 2, 10, 15, 20]) , which of the following expression(s) would be evaluated as True ?