ACTIVITY 19 / 50
Try as many times as you needWhile a condition is true
Let’s understand
while repeats a block while its condition is true. Something must change inside the loop or it may never finish. In this workshop, use Stop if a program runs too long.
Listen to the explanation
Example
n = 0
while n < 2:
print(n)
n = n + 1Print 1, 2 and 3 on separate lines using while.
I need a hint
Start with n = 1; increase n by 1 after printing.
How to find an error
- Read the last line of the error message.
- Find the indicated line. Check quotes, parentheses and indentation.
- Change one thing and run again.
main.py
4 spaces
Your draft stays in this browser.
Result
PythonYour program’s output will appear here. Click Run.
Мой профиль