Challenge: Repeat Yourself
Explore how to use for and while loops in Python to repeat actions and automate tasks. Learn to adjust loop conditions and ranges, understand repetition control, and practice with interactive challenges. This lesson helps you build foundational skills in programming logic and effective code structuring.
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.