PYTHON LESSON

Topic 13/63 · Phase 2: Logic

while Loop — Python lesson on EduBard (phase: Logic)

while Loop

Main idea

while repeats until condition becomes False.

Tip

Update loop variable each round.

Watch out

Infinite loops.

Read this next

You will study while Loop. It belongs to the Logic phase.

Remember this:
while repeats until condition becomes False.

Practice step by step. Do not rush. Each run should show you something new.

Tip:
Update loop variable each round.

Avoid this:
Infinite loops.

Your challenge:
Countdown from 10 to 1.

Go to the challenge lab below. Fix errors until the output looks right. Then press the green button to complete the topic.

Example code

Copy this example if it helps. Change it so it matches while Loop.

# Topic: while Loop
def main():
    sample = "edit me"
    # TODO: apply while Loop concept here
    result = sample
    print("Result:", result)

if __name__ == "__main__":
    main()

Challenge

Countdown from 10 to 1.

Before you can finish: your output should include at least 8 characters; at least 1 non-empty line(s); must contain (letters can be upper or lower case): "10", "1"; no crash traceback—fix errors until the program runs cleanly.

Use Run. Read the output. Change your code until the task is done.

Starter reference

# Challenge starter for while Loop
def solve():
    # Write your solution here
    pass

print("Update solve() and run")

Your code

The first Run may load Python in your browser (one-time). Later runs are faster.



    
    

Navigation