Quiz Space

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

Question 2: Consider the following code snippet that writes student d…

Question 2

+3 marksOne correct option

Consider the following code snippet that writes student details to a CSV file named "employees.csv": def save_data(data): f = open('employees.csv', 'w') f.write('Name,Salary\n') for i in range(len(data)): emp, sal = data[i] row = f'{emp},{sal}' if i != len(data) - 1: row = row + '\n' f.write(row) f.close() data = [ ('Alice', 75000), ('Bob', 64000), ('Charlie', 82000), ('Diana', 71000), ('Eve', 69000) ] If the save_data(data) function is called with the list data as shown above, what will be the contents of the file "employees.csv"?

  1. A

    Name,Salary Alice,75000 Bob,64000 Charlie,82000 Diana,71000 Eve,69000

  2. B

    Alice,75000 Bob,64000 Charlie,82000 Diana,71000 Eve,69000

  3. C

    Salary,Name Alice,75000 Bob,64000 Charlie,82000 Diana,71000 Eve,69000

  4. D

    Name Salary Alice,75000 Bob,64000 Charlie,82000 Diana,71000 Eve,69000

  5. E

    Salary,Name 75000,Alice 64000,Bob 82000,Charlie 71000,Diana 69000,Eve

Show answer

Correct answer

  • A

    Name,Salary Alice,75000 Bob,64000 Charlie,82000 Diana,71000 Eve,69000

Question 2 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 3 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. Q3What will be the output of the following Python code? string1 = 'database' string2 = 'baseball' L = [] for i in range(l…
  3. Q4What is the output of the following snippet of code? sentence = 'python,is,fun,and,learning,python,is,great' D = dict()…
  4. 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…
  5. 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…
  6. Q7employees is a list of tuples. Each tuple is of the form (name, salary) . Select all snippets of code that create a lis…
  7. Q8Consider the following snippet: f = open('employees.csv', 'r') D = dict() for line in f: name, department, salary = lin…
  8. Q9Consider the following snippet of code: def analyze_string(t, k): freq = {} for ch in t: freq[ch] = freq.get(ch, 0) + 1…
  9. 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…
  10. 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…
  11. 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…
  12. 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 …
  13. Q14What is the output of the following snippet of code? def doSomething(x, y): if x < y: return 0 return 1 + doSomething(x…
  14. 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…
  15. 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…
  16. Q17Consider 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…
  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…