Loops in Python
שאלות 10
מפתח התשובות מוצג למורים מחוברים.
-
-
-
Identifying an infinite loop
Which of the following loops never ends?
while x < 10: print(x) (with x = 0 before the loop, and x is never changed inside the loop)
while x < 10: x = x + 1 (with x = 0 before the loop)
for i in range(-5): print(i)
for i in range(10): x = x + 1
A while loop keeps running as long as its condition stays True. Ask yourself whether anything inside the loop could make the condition False. -
-
-
-
The else clause of loops
In Python, when does the else block attached to a while loop run?
Only when the condition is True at the very start
Only when a break statement is executed inside the loop
Every time after each iteration of the loop
When the loop ends because its condition became False, and not because of a break
Compare what happens when a loop finishes normally with what happens when it is exited early by break. -
-
-
Choosing the right loop type
A programmer needs to process every item of a list exactly once, from the first item to the last. Which Python loop is the most natural choice for this task?
for loop
goto loop
while loop
do-while loop
Think about which loop is designed to iterate over the items of a sequence, and which one is built around a condition instead.
פרטים
- מקצועות
- שפות תכנות
- תגיות
- נוסף על ידי AI for loops נוסף על ידי AI while loops נוסף על ידי AI range function נוסף על ידי AI nested loops נוסף על ידי AI loop counters
- קהל יעד
- תיכון · כיתות י׳–י״ב
- רמת קושי
- 6 מתוך 10
- שפה
- אנגלית
- מי יכול לראות
- כולם
- הושלם על ידי AI
- מה שמסומן בניצוץ נוסף על ידי AI.
- נוצר באמצעות AI
- Claude Haiku 5.5
- נוצר
תגובות