Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
Write a while loop that prints numbers from 1 to 5.
Remember to increment the variable inside the loop!
Create a while loop that stops when a variable reaches 10.
What condition will make sense to stop at 10?
What does a while loop do in Python?
Think about when the code will stop running.
True or False: A while loop can cause an infinite loop if the condition is never met.
Consider what happens if you forget to update your condition.
Write a program that finds all the prime numbers up to a given input number using a while loop.
You’ll need to check divisibility for each candidate prime.
Create a 'guess the number' game using a while loop where the user has to guess a number between 1 and 50.
Keep track of the number of attempts!
6 more questions in this section. Enroll free to practise them all.
Enroll free