Skip to content » Python Unit Home » Continuous Repetition with While Loops

Continuous Repetition with While Loops


Introduction to While Loops

YouTube blocked? Use the Google Drive version


Cheat Sheet

Cheat Sheet

#Example 1
x = 0 
while x < 5:
    x += 1

#Example 2
name = ""
while name.lower() != "mr west":
    name = input("Who is the best teacher?")

#Example 3
total = 0
while total <= 20:
    amount = int(input("How much to add?"))
    total = total + amount

#Example 4      
tries_left = 5
correct = False
while tries_left > 0 and correct == False:
    answer = input("What is 5 times 5?")
    if answer == "25":
        correct = True
        tries_left = tries_left - 1

if correct:
    print("Well done!")

#Example 5
while True:
    num = input("Please enter a number")
    if not num.isdigit():

    elif num == 0:
        num = int(num)
        print("The square of the num is:", num * num)

Printable Version

Challenge 13

Challenge 13 – Login Screen App

YouTube blocked at school? Use the Google Drive Version 

Login Screen App


  • Create an app that repeatedly asks the user for their password until the correct password is entered.


  • Adapt your program so that it asks for both a username and password.
  • Use os.system(‘clear’) and time.sleep(1) to improve your app.



  • Limit the number of login attempts using a variable to keep track


Challenge 14 – Joke App

Everybody loves jokes! Create an app that asks users if they want to hear a joke.
If they answer yes tell them a joke.
Keep repeating the question until they answer yes.

YouTube blocked at school? Use the Google Drive Version.


  • Ask the yes/no question, when they answer yes break out of the loop and tell the joke.


  • If they answer no, provide suitable feedback and ask the question again.
  • Use the .lower()  method to accept lower or uppercase input.


  • Clear the screen and use time.sleep() where appropriate make your app awesome.
  • Add some ASCII Art to your joke app.


Challenge 15 – Darts 501 to zero Score calculator

In darts players start at 501 and work their way down to zero. Create an app that keeps track of the player’s score and tells them when they have reached zero.


  • The app should create a score variable, set it to 501 and then keep asking the user to enter their score until they get down to zero.


  • The program should tell the user how many throws they took.
  • The program should only accept number inputs and only accept inputs between 0 and 180.


  • Create a two player version of the game and let the players know who has won.


Challenge 16 – Random number guesser game

You should write a program that asks the user to guess a random number.


  • Generate a random number between 0 and 100 and ask the user to guess the number.
  • Keep asking the user to guess until they correctly guess the hidden number.


Give the user a hint each time to tell them if they are too high or too low.


  • Keep track of how many guesses the user made and tell them at the end.
  • Add the option to select a difficulty level and give them a different number of guesses depending on the option selected.
    • Easy – unlimited tries
    • Medium – 10 tries
    • Hard – 5 tries.



How to display ASCII Art in your programs