Hey!
You should create the “index” variablebefore the print statement and inside the for loop. That way, you can track or modify the position of each character. Try this:
for char in text:
# Create the index variable here
print(char)
Give it a shot, and let me know if you need more help!
A loop is a way to repeat a block of code multiple times without writing it over and over. It helps automate tasks and makes code more efficient. Here are some common types of loops in Python:
For Loop – Goes through items in a sequence (like a string or list).
text = "Hello"
for char in text:
print(char) # Prints each letter one by one
Output:
H
e
l
l
o
While Loop – Keeps running as long as a condition is True.
x = 0
while x < 5:
print(x)
x += 1 # Stops the loop once x reaches 5
Output:
0
1
2
3
4
Infinite While Loop – Runs forever unless you stop it manually.
while True:
print("This will run forever!")
Output:(Repeats forever until stopped)
This will run forever!
This will run forever!
This will run forever!
...
You’ll learn more about for, while and others loops and different types in the upcoming lessons!
Loops are super useful for handling repetitive tasks. Keep going, and it’ll all start making sense! Let me know if you have any questions.
That’s great! Since the for loop worked for you, let’s focus on it.
A for loop repeats code for each item in a sequence (like a string or list).
Try this:
for i in range(5):
print(i) # Prints numbers 0 to 4
Output:
0
1
2
3
4
You can also loop through words:
word = "Python"
for letter in word:
print(letter) # Prints each letter one by one
Keep practicing, and it’ll click soon! Let me know if anything is unclear.
Don’t worry— in the upcoming lessons, you’ll learn more about for loops and even get into while and while True loops. Just keep going, and if you get stuck at any point, feel free to ask!