# Learn String Manipulation by Building a Cipher - Step 42

**URL:** <https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [May 13, 2024, 12:08am UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948 "2024-05-13T00:08:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcfbros](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@mcfbros](https://forum.freecodecamp.org/u/mcfbros)\
**Post date:** [May 13, 2024, 12:08am UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/1 "2024-05-13T00:08:35Z")

</div>

### Tell us what’s happening:

what have i done wrong  
text = ‘Hello World’  
shift = 3  
alphabet = ‘abcdefghijklmnopqrstuvwxyz’  
encrypted\_text = ‘’

for char in text.lower():  
if char == “space”:  
print (“space”)  
index = alphabet.find(char)  
new\_index = index + shift  
encrypted\_text += alphabet[new\_index]  
print(‘char:’, char, ‘encrypted text:’, encrypted\_text)  
pass

### Your code so far

```py

# User Editable Region

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

for char in text.lower():
    if char == "space":
        print ("space")
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)
    pass

# 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/124.0.0.0 Safari/537.36 Edg/124.0.0.0`

### Challenge Information:

Learn String Manipulation by Building a Cipher - Step 42

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-42)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [May 13, 2024, 12:11am UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/2 "2024-05-13T00:11:54Z")

</div>

> print the result of comparing `char` with a space (`' '`)

A space string, a space character in quotes. Not the word “space” but " "

In a sentence, if you are going through it character by character, you will encounter spaces. “I”, “n”, " ", “a”, " ", “s”, “e”

Don’t use `if` just print the result of the comparison

---

<div class="post-metadata">

**Author:** ![mcfbros](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@mcfbros](https://forum.freecodecamp.org/u/mcfbros)\
**Post date:** [May 13, 2024, 9:08pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/3 "2024-05-13T21:08:42Z")

</div>

still wrong do you have any more ideas but thanks  
text = ‘Hello World’  
shift = 3  
alphabet = ‘abcdefghijklmnopqrstuvwxyz’  
encrypted\_text = ‘’

```auto
for char in text.lower():
    char == "space"
    print ("space")
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)
    pass

```

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [May 13, 2024, 9:12pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/4 "2024-05-13T21:12:55Z")

</div>

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [May 13, 2024, 9:15pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/5 "2024-05-13T21:15:12Z")

</div>

> [@mcfbros](#):
>
> `char == "space"`

You’re still comparing `char` to the word space, not a space character

```auto
"space" #the word space
' ' #space character

```

And you are printing the word “space”, not the comparison (the expression with `==` is a comparison because it compares the left and right sides of the `==` and returns `true` if they are equal and `false` if they are not).

---

<div class="post-metadata">

**Author:** ![mcfbros](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@mcfbros](https://forum.freecodecamp.org/u/mcfbros)\
**Post date:** [May 13, 2024, 9:28pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/6 "2024-05-13T21:28:35Z")

</div>

still wrong  
text = ‘Hello World’  
shift = 3  
alphabet = ‘abcdefghijklmnopqrstuvwxyz’  
encrypted\_text = ‘’

for char in text.lower():  
if char == " “:  
print(”==")  
encrypted\_text == char  
else:  
index = alphabet.find(char)  
new\_index = index + shift  
encrypted\_text += alphabet[new\_index]  
print(‘char:’, char, ‘encrypted text:’, encrypted\_text)  
thanks tho this is my first time trying coding

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [May 13, 2024, 9:39pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/7 "2024-05-13T21:39:59Z")

</div>

Can you try formatting this as code so the indentation is visible?

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [May 13, 2024, 9:42pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/8 "2024-05-13T21:42:05Z")

</div>

```auto
char == " "

```

This is a comparison, comparing `char` and `" "`

```auto
"=="

```

This is a comparison operator

No need for `if` because the instructions don’t mention it

---

<div class="post-metadata">

**Author:** ![mcfbros](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@mcfbros](https://forum.freecodecamp.org/u/mcfbros)\
**Post date:** [May 13, 2024, 9:47pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/9 "2024-05-13T21:47:05Z")

</div>

under that i put  
print(“false”)  
what should it be

 ![Screenshot 2024-05-13 224836](https://global.discourse-cdn.com/freecodecamp/original/4X/4/6/d/46dcaf4ffa7b39c9cc9f178cbe9698a391683e29.png)

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [May 13, 2024, 9:59pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/10 "2024-05-13T21:59:02Z")

</div>

The loop will cycle through each character in the sentence. You don’t know if it will be a letter or a space.

Instead of printing “False”, just print the comparison:

```auto
char == " "

```

This is the comparison

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [November 12, 2024, 9:59am UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-42/689948/11 "2024-11-12T09:59:13Z")

</div>

Closed on November 12, 2024, 9:59am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
