Tell us what’s happening:
Why does my Caesar cipher code return -1 for uppercase letters in Python?
I’m trying to implement a simple Caesar cipher in Python. I want to shift each letter in a string by 3 positions using the English alphabet. Here’s the code I have so far:
text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
index = alphabet.find(text[0])
When I run this, I get -1 for the first character because it’s uppercase (‘H’). I learned that .find() is case-sensitive, so I tried using .lower()
Your code so far
# User Editable Region
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(text.lower())
print(alphabet.find(text[0].lower()))
# 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/140.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 18
