Bird
0
0

This code snippet is meant to organize a list of tasks by priority:

medium📝 Analysis Q14 of 15
Intro to Computing - What is Computing
This code snippet is meant to organize a list of tasks by priority:
tasks = ["clean", "shop", "study"]
priority = [2, 1, 3]
organized = []
for i in range(len(tasks)):
    organized.append(tasks[priority[i]])
print(organized)

What is the error in this code?
AThe print statement is missing parentheses
BUsing priority values as indexes directly causes an error
CThe tasks list is empty
DThe for loop has wrong range length
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code's goal and indexing

    The code tries to reorder tasks by priority using priority values as indexes.
  2. Step 2: Identify index error

    Priority values are 1, 2, 3 but list indexes start at 0, so tasks[3] causes an IndexError.
  3. Final Answer:

    Using priority values as indexes directly causes an error -> Option B
  4. Quick Check:

    Indexing error from priority values = Using priority values as indexes directly causes an error [OK]
Quick Trick: Remember list indexes start at 0, not 1 [OK]
Common Mistakes:
  • Thinking print needs fixing in Python 3
  • Assuming tasks list is empty
  • Ignoring index range errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Intro to Computing Quizzes