Quiz Space

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

Question 11: Consider the following Python code:\ with open("data.txt…

Question 11

+2 marksNumerical answer

Consider the following Python code:
with open("data.txt", "w") as f:
for i in range(3):
for j in range(i + 1):
f.write(f"Line {i}-{j}" + ("\n" * (j + 1)))
with open("data.txt", "r") as f:
count = len(f.readlines())
print(count)
What is the output of the given code?

Show answer

Correct answer: 10

Question 11 of 20 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 2 marks.

More questions from this paper

  1. Q1What will be the output of the following Python code?\ words = ["jacket", "cap", "scarf", "hat", "sock"]\ result = []\ …
  2. Q2Consider the following Python code:\ def evaluate_score(score):\ if score >= 90:\ if score == 100:\ print("Perfect Scor…
  3. Q3Consider the following Python code:\ class Employee:\ def init(self, name):\ self.name = name\ self.role = "Employee"\ …
  4. Q4What will be the total number of lines printed when the following code is executed? scores = {\ "Aarav": [10, 20, 30],\…
  5. Q5What will be the output of the following code snippet?\ data = [(4, 7), (5, 8), (6, 6), (9, 3)]\ total = 0\ for a, b in…
  6. Q6What will be the output of the following code?\ items = ["apple", "banana", "cherry", "date", "fig", "grape", "kiwi"]\ …
  7. Q7Consider the use of the map() function in the following code snippets. Select all options that has the value [4, 9, 16,…
  8. Q8Which of the following statements about the exception handling behavior are TRUE? Select ALL that apply.\ def safe_divi…
  9. Q9Consider the following code snippet:\ def update_scores(scores, bonus):\ updated = []\ for score in scores:\ updated.ap…
  10. Q10Consider the following Python code:\ names = ["Aarav", "Bhuvan", "Charan", "Deepa"]\ marks = [88, 76, 92, 81]\ bonus = …
  11. Q12Consider the following Python code:\ a1 = (3, 6, 9, 12, 15, 18, 21, 24)\ a2 = a1[2:7]\ a3 = a2[::-1]\ a4 = tuple(x for …
  12. Q13Consider the following Python code:\ def transform(words):\ if not words:\ return []\ first = words[0][::-1]\ if first …
  13. Q14Consider the following Python code snippet:\ colors = ['red', 'blue', 'green', 'red', 'blue', 'red', 'yellow']\ freq = …
  14. Q15Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  15. Q16Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  16. Q17Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  17. Q18Consider the following Python code and answer the sub-questions:\ class Vehicle:\ total_vehicles = 0\ all_models = []\ …
  18. Q19Consider the following Python code and answer the sub-questions:\ class Vehicle:\ total_vehicles = 0\ all_models = []\ …
  19. Q20Consider the following Python code and answer the sub-questions:\ class Vehicle:\ total_vehicles = 0\ all_models = []\ …