Quiz Space

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

Question 10: What is the output of the following snippet of code? def…

Question 10

+3 marksWritten answer

What 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(1024, 2))

Show answer

A written answer, not marked automatically.

Question 10 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. 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. 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…