str1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
str2 = str1.lower()
x = int(input("请选择加密还是解密"))
a = input("请输入密文或是明文")
if x == 0:
    for i in a :
        if i in str2:
            b = str2.find(i)
            c = (b + 3) % 26
            print(str2[c],end='')
        elif i in str1:
            b = str1.find(i)
            c = (b + 3) % 26
            print(str1[c], end='')
        elif i in ' ':
            print(' ', end="")
        else:
            print(i, end="")
elif x == 1:
    for i in a :
        if i in str2:
            b = str2.find(i)
            c = (b - 3) % 26
            print(str2[c],end='')
        elif i in str1:
            b = str1.find(i)
            c = (b - 3) % 26
            print(str1[c], end='')
        elif i in ' ':
            print(' ', end="")
        else:
            print(i, end="")
else:
     print("please choice the 0 or 1")            

  终于找到了能把解密和加密放在一起的方法了