Quiz Space

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

Question 9: Consider the following snippet of code: def analyze_strin…

Question 9

+3 marksOne or more correct options

Consider the following snippet of code: def analyze_string(t, k): freq = {} for ch in t: freq[ch] = freq.get(ch, 0) + 1 is_unique = all(c < k for c in freq.values()) if is_unique: print(True) else: print(False) if input_str.isdigit(): print(True) else: print(False) analyze_string(input_str, 2) input_str is a string variable that has already been defined. The above code runs without any errors. The output when the code given above is executed is as follows: True True Which of the following statements are True? Note that your answer should hold for any value of the string input_str that results in the above output.

Select all that apply.

  1. A

    input_str contains only numeric characters

  2. B

    input_str could contain alphabets

  3. C

    The first character of input_str occurs exactly two times

  4. D

    All elements of input_str occur exactly one time

  5. E

    All elements in input_str occur at least two times.

Show answer

Correct answers

  • A

    input_str contains only numeric characters

  • D

    All elements of input_str occur exactly one time

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