Learn String Manipulation by Building a Cipher - Step 16

Tell us what’s happening:

Hi! I really don’t get the description of this one. I find my self trying in every single way, searched on the internet and even used ChatGPT without breakthrough. ChatGPT technically solved it, but not on this tasks terms.

I have tried

shifted=index+shift
shifted = alphabet[(index + shift)

and even

shifted_index = (index + shift)

but nothing seems to be working. I understand that the answer is supposed to be 10. But can someone please elaborate the question more detailed or just give me an example of a different code at least so that I might understand?

Your code so far


/* User Editable Region */

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)

shifted = (index+shift)

/* 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/119.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 16

Hi there and welcome to our community!

Declare a variable named shifted and assign it the alphabet letter at index plus shift .

You’re not too far off with this try:

However, this is syntactically incorrect as you only have one square bracket. Also, the parentheses are not required here.

2 Likes

Thanks! But what are the difference between using and () or none of them? Cause a bit further in on a different task it did not want but rather none.

The different types of brackets in Python generally serve different, distinct purposes:

alphabet = 'abcdefghijklmnopqrstuvwxyz'
print(alphabet[0])
# prints 'a'

The square brackets above are used to access a particular index of the alphabet string.
The parentheses above are used to call the print method. The contents of the parentheses are the arguments/parameters sent to the method, which determine the output.

There are other uses for parentheses, square brackets (and also curly brackets), but you’ll pick them up as you go along.

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