-2
def encrypt(text, key, direction):
if direction == 1: #The direction is either -1, or 1. If it is 1, it goes right. Otherwise, it will go left.
emptys=''
for x in text:
b = ord(x) #b is the individual characters after the ord() function
b+=key
if b<=122:
n = chr(b) #n is the converted letter of the encrypted ASCII number
emptys+=n
else:
o=b-90
q=chr(o)
emptys+=q
return emptys
else:
emptys=''
for x in text:
b = ord(x) #b is the individual characters after the ord() function
b=b-key
if b>=32:
n = chr(b) #n is the converted letter of the encrypted ASCII number
emptys+=n
else:
o=b+90
q=chr(o)
emptys+=q
return emptys
您应该格式化您的代码,而且:如果此代码没有问题,则它不属于Stack Overflow。为了改进**并假设此代码有效**,您可能想在[代码评论](http://codereview.stackexchange.com/)上尝试运气。 –
您的代码太长,变量名太短,符号之间没有足够的空白。您应该能够通过重构仅使用一次的变量来将其降低到大约一半 –