Learn String Manipulation by Building a Cipher - Step 42

Tell us what’s happening:

I try differents things, and read lots of topics in the help forum. But cannot find what’s wrong here :confused:

Your code so far


# User Editable Region

for char in text.lower():
    if char == ' ':
        encrypted_text += char
        index = alphabet.find(char)
        new_index = (index + shift) % len(alphabet)
        encrypted_text += alphabet[new_index]

print('Encrypted text:', encrypted_text)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 42

1 Like

(I also use chatGPT at the end, that’s why my code maybe looks weird…)

Hi @Hibufu

Where are the first four lines of code?

Happy coding

alphabet = ‘abcdefghijklmnopqrstuvwxyz’ # Define the alphabet
shift = 3 # Example shift value
text = “hello world” # Example input text
encrypted_text = “” # Initialize the encrypted text

Are they still at the top in the editor?

No…

that’s why you have that traceback in the terminal, you need those lines

1 Like

I wouldn’t trust ChatGPT, and I wouldn’t delete anything unless the instructions ask for it.

2 Likes

So now, i’m locked? :confused:

didn’t you just paste them in a post here?

there is also a reset button you can use to restore the code to the start of the step

2 Likes

I don’t know what ‘locked’ means? You should be able to put those lines back

Alright, thanks guys!..

You help me to come back from far. Just some bad ideas or command from my side make me lost. .
Lesson done! :v:

3 Likes

i got answer

code removed by moderator

hi @clevermiraz

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.