Learn String Manipulation by Building a Cipher - Step 26

Tell us what’s happening:

so where should i create the variable i been stuck on step for days please help

Your code so far

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'

# User Editable Region

 for char in text:
    print(char)
    

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 26

Hey! :wave:
You should create the “index” variable before 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! :blush:

thank u so much i will try it and whats a loop

You’re welcome! :blush:

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! :rocket:

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. :blush:

thanks for explaining to be honest i didnt understand very much but i got it and the first one u helped right it worked yay

1 Like

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! :blush: