Python Forum
Caesar Cypher--- I don't understand why it doesn't work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Caesar Cypher--- I don't understand why it doesn't work
#11
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.
Reply
#12
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
Reply
#13
Glad you got it working, and thanks for sharing the solution!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 928 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,771 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 882 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 1,704 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 4,178 May-30-2022, 03:31 PM
Last Post: bowlofred
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 2,002 Dec-18-2021, 02:38 AM
Last Post: knight2000
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,695 Oct-30-2021, 11:20 PM
Last Post: Yoriz
  Process doesn't work but Thread work ! mr_byte31 4 2,603 Oct-18-2021, 06:29 PM
Last Post: mr_byte31
  Trying to understand how isinstance(values, collections.Iterable) work. quazirfan 7 4,177 Aug-10-2021, 08:10 AM
Last Post: snippsat
  Psycopg2 doesn't work with python2 MedianykEugene 3 2,939 Aug-10-2021, 07:00 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020