MTEL Digital Literacy and Computer Science

Category - Digital Lit and CS

Use the pseudocode below to answer the question that follows.
1
 # the index of list_one begins at 0
2
3   list_one = ["March", "April", "May", "June", "July"]
4
5   # execute selected code here
6   print(list_one[i])

A student wants to print out the elements in
list_one. Which of the following replacements for # execute selected code here on line 5 is correct?
  1. for (i = 0; i < 4; i = i + 1)
  2. for (i = 0; i <= 4; i = i + 1)
  3. for (i = 1; i < 5; i = i + 1)
  4. for (i = 1; i <= 5; i = i + 1)
Explanation
Correct Response: B. The index needs to start at 0, end at 4, and increase by 1. A is incorrect because the index ends at 3. C is incorrect because the index starts at 1. D is incorrect because the index starts at 1 and ends at 5.
Was this helpful? Upvote!
Login to contribute your own answer or details

Top questions

Related questions

Most popular on PracticeQuiz