Courseiva
hardMultiple ChoiceObjective-mapped

220-1102 Practice Question: A technician is writing a Python script to…

A technician is writing a Python script to automate the cleanup of user profiles on a Windows server. The script must iterate through all user profile folders in 'C:\Users', check the last modified date, and delete profiles older than 90 days. Which scripting concept is essential for this task?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

A for loop to iterate over folders

This question tests understanding of loops, conditionals, and file system operations in a scripting language. A 'for' loop is needed to iterate through each folder, combined with an 'if' statement to check the date condition. Without a loop, the script would only process one folder. Error handling is important but not the core concept for iteration.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Error handling with try-except

    Why it's wrong here

    While "try-except" blocks are crucial for creating robust scripts that gracefully handle unexpected issues like file not found errors or permission denied exceptions during deletion, they are not a fundamental component for the *initial* logic of iterating through a collection of folders. The core requirement for processing each folder sequentially is a looping construct, not error management, making error handling a secondary, albeit important, consideration for script resilience.

  • A for loop to iterate over folders

    Why this is correct

    A "for" loop is the most appropriate and Pythonic construct for iterating over a known collection of items, such as a list of folders obtained from a directory listing. It provides a clear and concise way to process each folder sequentially, executing a block of code for every item until the collection is exhausted. This direct iteration over an iterable object is fundamental to systematically examining and acting upon each folder, making it essential for the task.

  • A while loop with a counter

    Why it's wrong here

    Although a "while" loop *could* technically be used with a counter to iterate through folders (e.g., by indexing into a list of folder names), it is generally considered less idiomatic and more cumbersome in Python for this specific task. It would require manual management of an index variable and a termination condition, introducing more potential for off-by-one errors compared to the direct, cleaner iteration provided by a "for" loop over an iterable.

  • A function to calculate date difference

    Why it's wrong here

    While calculating date differences is undoubtedly a critical component of the script's overall logic for determining which folders to delete based on age, it is not the fundamental concept required for *iterating* through the folders themselves. The question specifically asks for the essential element to process each folder sequentially, which is a looping construct, not a specific computational function that operates on individual folder metadata.

About these practice questions

This 220-1202 question is part of Courseiva's 495-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 220-1202 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 220-1202 exam.