Reputation: 1
I'm facing deep troubles with a script I was trying to write to answer a question on a course I was doing. I keep on getting SyntaxError: invalid syntax line 138 which was a bit odd. Here is my script. It would be wonderful if somebody could explain how to solve this. Thanks
class Message(object):
def __init__(self, text):
self.message_text = text
self.valid_words = load_words(WORDLIST_FILENAME)
def get_message_text(self):
return self.message_text
def get_valid_words(self):
return self.valid_words[:]
def build_shift_dict(self, shift):
lc_str = string.ascii_lowercase
uc_str = string.ascii_uppercase
shifted_dict = {}
for ltr in lc_str:
if lc_str.index(ltr) + shift < 26:
shifted_dict[ltr] = lc_str[lc_str.index(ltr) + shift]
else:
shifted_dict[ltr] = lc_str[lc_str.index(ltr)-26+shift]
for ltr in uc_str:
if uc_str.index(ltr) + shift < 26:
shifted_dict[ltr] = uc_str[uc_str.index(ltr) + shift]
else:
shifted_dict[ltr] = uc_str[uc_str.index(ltr)-26+shift]
return shifted_dict
def apply_shift(self, shift):
cipher = self.build_shift_dict(shift)
ciphertext = ""
for char in self.message_text:
if char in cipher:
ciphertext = ciphertext + cipher[char]
else:
ciphertext = ciphertext + char
return ciphertext
Upvotes: 0
Views: 520
Reputation: 60143
Between these two lines:
shifted_dict = {}
for ltr in lc_str:
You have a non-ASCII character ('\xe2'
). Delete it.
(Python tells you exactly this if you try to load your code in a Python interpreter.)
Upvotes: 1