Python Forum

Full Version: Caesar Cypher--- I don't understand why it doesn't work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Just to amplify LeShakal' response:
The computer doesn't have a brain and therefore doesn't 'understand' anything. It reacts to whatever program is running at the time - in this case the Python interpreter. This understands Python syntax not the vagaries of the human mind, so there is no question of it 'understanding' what you mean. When programming you are supposed to be the 'smart' one , telling the 'dumb' computer exactly what you want it to do. If it can't make sense of what you want of it it quite rightly gives up with an error message. Then it is up to you to spot your mistake and correct it. This is the art of programming.
So do as LeShakal suggests, look at line 12 and spot your mistake.
Thank you all for your help. My program is correct and sheep is now furrc.

Here is how it looks:
alphabet= "abcdefghijklmnopqrstuvwxyz"
cleartext= input()
cleartext=cleartext.lower()
def encrypt(cleartext):
    codedtext = " "
    for character in cleartext:
            if character in alphabet:
                newcharacter= (alphabet.find(character) + 13) %26
                codedtext += alphabet[newcharacter]
            else:
                codedtext += character
    return codedtext
print(encrypt(cleartext))
Thank you--- I got return codedtext out of the loop that for character created
Glad you got it working, and thanks for sharing the solution!
Pages: 1 2