0

from cs50 import get_string import sys

def main(): if len(sys.argv) != 2: print("usage: python caesar.py key") exit(1) key = int(sys.argv[1]) translated = [] plaintext = get_string("Plaintext: ", end="")

for symbol in plaintext:
    if symbol.isalpha():
        translated.append(caesar(symbol, key))
    else:
        translated.append(symbol)

print("".join(translated))
exit(0)

def caesar(char, key):
    if char.isupper():
        return chr(((ord(char) - 65 + key) % 26) + 65)
    else:
        return(((ord(char) - 97 + key) % 26) + 97)

if name == "__ main__": main()

0

Looks like you have a space in "__main__" so your main function is never called.

  • Now I have this error: File "caesar.py", line 19, in main translated.append(caesar(symbol, key)) UnboundLocalError: local variable 'caesar' referenced before assignment. Please help – Bethuel Mavhungu Nov 5 '18 at 8:23
  • you've defined caesar inside of main. Perhaps move it out. – curiouskiwi Nov 5 '18 at 21:28
  • thanks it works – Bethuel Mavhungu Nov 6 '18 at 9:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .