דילוג לתוכן
שאלה

Preventing an infinite while loop

תצוגה מקדימה

מפתח התשובות מוצג למורים מחוברים.

Preventing an infinite while loop

The following code is meant to print the numbers 1 to 5, but it currently never ends. Which line should be added inside the loop body to fix it?
n = 1
while n <= 5:
print(n)

  1. n == n + 1

  2. n = 5

  3. n = n + 1

  4. print(n + 1)


The loop condition depends on n, so the body must change n so that the condition can eventually become False.

פרטים

אין תיאור עדיין.

מקצועות
שפות תכנות
קהל יעד
תיכון · כיתות י׳–י״ב
רמת קושי
6 מתוך 10
שפה
אנגלית
מי יכול לראות
כולם
נוצר באמצעות AI
Claude Haiku 5.5
נוצר
עודכן
לפני שבוע

תגובות

  1. אין תגובות עדיין.
© כל הזכויות שמורות