Quiz Space

Programming in Python · Quiz 1 · 13 Jul 2025 · May 2025 term

Question 10: Consider the following snippet of code. What will the ou…

Question 10

+4 marksNumerical answer

Consider the following snippet of code. What will the output be?
names = ["alice", "bob", "charlie", "david", "eve"]
result = 0
short = []
for name in names:
if len(name) < 4:
short.append(name)
elif len(name) == 5:
result += 1
elif 'a' in name:
result += 2
print(len(short) + result)

Show answer

Correct answer: 6

Question 10 of 14 in the IIT Madras BS Programming in Python (Python) Quiz 1 paper sat on 13 Jul 2025, in the May 2025 term (IIT M DIPLOMA AN EXAM QDD2 13 July 2025). It carries 4 marks.

More questions from this paper

  1. Q1Consider the following code:\ text = " >>> Hello, Python! \<\<\< "\ to_strip = " \<>"\ A = text.strip(to_strip)\ B = te…
  2. Q2Consider a Python program that takes a sentence (which may contain both uppercase and lowercase letters, spaces, and pu…
  3. Q3What is the output of the following Python code?\ data = ["alpha", "beta", "gamma"]\ data[1] = data[1].replace("e", dat…
  4. Q4We want to print the following pattern.\ 1111\ 1001\ 1011\ 1111\ Which of these two snippets is correct?\ Snippet-1\ n …
  5. Q5P is a non-empty list of distinct integers that has already been defined. Which of the following statements are true at…
  6. Q6Consider the following Python code:\ def process(x, y):\ if x > y:\ return x - y\ elif x \< y:\ return y - x\ else:\ re…
  7. Q7Consider the following snippet of code. What will the output be?\ result = 0\ for i in range(1, 4):\ for j in range(1, …
  8. Q8What is the output of the following snippet of code? Enter an integer as your answer. lst = ['IIT', ['Madras', '2025'],…
  9. Q9What is the output of the following snippet of code? Enter an integer as your answer. lst = [x for x in [1,0,-2]]\ resu…
  10. Q11What is the value of output after executing the given code?
  11. Q12Which of the following changes would also include SQL in the final result?
  12. Q13What is the value of output after executing the given code snippet?
  13. Q14In the given code, if we change the condition to if element % 2 == 0 at line 7, then what is the value of output after …