Tell us what’s happening:
im not getting the exact code to run to get exact output .
Your code so far
# User Editable Region
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shift = 5
shifted_alphabet = alphabet[shift:start] + alphabet[shift:stop]
print(shifted_alphabet)
# 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/142.0.0.0 Safari/537.36
Challenge Information:
Build a Caesar Cipher - Step 4
shifted_alphabet = alphabet[shift:start] + alphabet[shift:stop]
You were asked to concatenate so don’t change what was already on this line, you need to add to it.
On the part you concatenated:
alphabet[shift:stop]
You have started at shift. What does shift represent in your variable? Why have you started at that?
‘stop’ is a placeholder in the example, you need to put a number there, or a representation of a number from your code.
shift is assigned to the integer 5. So basically the word ‘shift’ in your code is not a command its just equal to the number 5 and in the slicing operation, numbers are used to indicate where to start extracting characters from the string from and where to stop extracting.
it works like this - var[where we start picking from : stop just before here]
for example :
showcase=“beautiful”
shift=3
output=showcase[0:shift]
print(output)
the number 0 in the above example is just saying we want to start picking/extracting letters or characters from the beginning of the string “beautiful” which is “b”
if the number 0 is “b” then the number 1 is “e” and number 2 is “a” and so on and so forth.
The variable “shift” which is just the number 3 says extract the letters/characters from 0-2 and stop there.
so if we count from the beginning of “beautiful” as the number 0 is implying here, it means we’re starting from the letter ‘b’ and counting 2 letters in front of ‘b’ then we stop there.
this results in “bea” from the string “beautiful”
same thing happens if i do this:
output=showcase[0:3]
this gives me the same “bea” from “beautiful”
the word “shift” was just assigned to the number 3 that’s all.
by the way if you leave any of the indicators empty (you dont say where to start OR where to stop, it will just select everything from the beginning or to the end)
what i mean is (using the example showcase=”beautiful”)
if i do output=showcase[0:] - this will select everything from point 0(which is the beginning) all the way to the end.
if do output = showcase[:5] - this will select from the beginning all the way to just before point 5 (“beaut”)