I searched and found a very similar question here Syntax Error when trying to define multiple functions in python?
but the question wasn't really answered
I am getting a syntax error at the second "def" . My indentation may be messed up here because I cannot figure out the formatting in this place....BUT it is correct in my program, indentation is not the issue.
def encryptChar(ch, key):
newOrd = ord(ch) + key % 26
if ord(ch) < 65:
newOrd = ord(ch)
elif ord(ch) < 91:
if newOrd > 90:
newOrd = newOrd - 26
elif newOrd > 122:
newOrd = newOrd - 26
newch = chr(newOrd)
return newch
def encryptString(string, key):
newString = ""
for i in range(len(string)):
newString += encryptChar(string[i], key)
return newString
def decryptString(string, key):
newString = ""
for i in range(len(string)):
newString += encryptChar(string[i], -1*key)
return newString
I'm GUESSING it has something to do with the functions all being top level. But how do I fix it? This is Python 2.7. (I could include the top function inside the other 2, but I am still left with 2 top level)
Thanks for any help!
IndentationError, not aSyntaxError. Nobody has been able to reproduce your problem, so triple check that you are actually using the code you posted here.