QuizzesLoops — for, while, range, enumerate & zip — Concept Check
intermediate
python

Loops — for, while, range, enumerate & zip — Concept Check

Questions on Loops — for, while, range, enumerate & zip. Python's for loop iterates over ANY iterable directly — no index bookkeeping. range generates number sequences; enumerate gives index+value; zip walks multiple sequences together.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Loops — for, while, range, enumerate & zip — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.You have a list of numbers and want to multiply each by 10. Which loop is most Pythonic?

    • Afor num in nums: num *= 10
    • Bfor i in range(len(nums)): nums[i] *= 10
    • Cfor i, num in enumerate(nums): nums[i] = num * 10
    • Dwhile i < len(nums): nums[i] *= 10
  2. 2.You want to iterate over two lists simultaneously. Which function should you use?

    • Aenumerate
    • Bzip
    • Crange
    • Dsorted
  3. 3.Given a dictionary 'marks = {"dsa": 85, "java": 90}', how do you iterate over key-value pairs?

    • Afor subject in marks.keys()
    • Bfor subject, mark in marks
    • Cfor subject, mark in marks.items()
    • Dfor mark in marks.values()
  4. 4.A loop iterates over a list of skills using 'for skill in skills'. What is the main advantage?

    • AFaster execution
    • BUses less memory
    • CNo need for index bookkeeping
    • DAutomatically sorts the list
  5. 5.What does the 'enumerate' function return when iterating over a list?

    • AValue and index pairs
    • BIndex and value pairs
    • COnly values
    • DOnly indexes
  6. 6.You have two lists of unequal length and use 'zip' to iterate over them. What happens?

    • AStops at the shortest list
    • BStops at the longest list
    • CRaises an error
    • DFills missing values with None
  7. 7.When should you prefer a 'while' loop over a 'for' loop in Python?

    • AWhen iterating over a fixed list
    • BWhen the loop depends on a condition
    • CWhen you want to iterate in reverse
    • DWhen you need index and value
  8. 8.A Python developer uses 'for i in range(len(items))' in a loop. What does this indicate?

    • AThey are using a while loop alternative
    • BThey may be coming from a Java background
    • CThey are handling multiple iterables
    • DThey are using the most efficient method