Search⌘ K
AI Features

Challenge: Repeat Yourself

Explore how to use Python loops to automate repetition by experimenting with for and while loops. Understand how conditions control looping, and practice by creating examples that repeat messages, count numbers, and interact with user input. This lesson helps you gain confidence in applying loops to build smarter, more efficient programs.

We'll cover the following...

In this activity, you’ll explore how loops can repeat actions for you, saving time and making your programs smarter. Your goal is to experiment with both for and while loops by changing how many times they run or what conditions stop them.

Start by thinking about what a loop does: it repeats a block of code again and again until a condition is no longer true. You can use loops to repeat messages, count numbers, or keep asking for input until a certain word is typed.

Here are a few fun ideas to try:

  • Idea 1: Print your name a few times to see how repetition works.

  • Idea 2: Make your loop count by twos (or any number you choose).

  • Idea 3: Create a loop that keeps running until the user types a specific word like "stop".

You can adjust the numbers in the range() function or change the loop’s condition to see how your program’s behavior changes. Each small tweak will help you understand how loops control repetition in Python.

If you get stuck, remember, your AI mentor is here to give you a hint or help you figure out what’s happening in your loop!

# Write your code here.
The code keeps asking for input until we type “stop”