当执行遇到空格时,会执行else后面的代码,再加上1个空格,可以放在前面,加个continue继续下个循环
def encypt_func(txt, s):
result=""
for i in range(len(txt)):
if (txt[i] == " "):
result += " "
continue
if (txt[i].isupper()):
result += chr((ord(txt[i]) + s - 65) % 26 + 65)
else:
result += chr((ord(txt[i]) + s - 97) % 26 + 65)
return result