包含字母和整数的Python列表

时间:2018-12-18 04:24:33

标签: python

def main():
    list_one = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '.', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
    list_two = ['4', 'R', '5', 'G', 'Z', '3', '2', 'D', 'A', 'E', 'X', 'Y', 'U', 'I', '6', 'W', '7', 'O', 'V', '8', 'F', 'Q', 'L', '0', 'J', '.', 'H', '9', 'C', 'B', 'N', 'S', 'P', 'M', '1', 'T', 'K']


    code = str(input("Enter message here. ")).upper()
    question = str(input("Would you like to encrypt or decrypt? ")).lower()


    if question == "encrypt":
       code_encrypt(list_one, list_two, code)
    #elif question == "decrypt":
    else:
        print("Invalid Input, Try Again")
        main()


def code_encrypt(x, y, z):
    message = ''
    for i in (z):
        for j in range(len(x)):
            if i == x[j]:
                message = message + repr(y[j])


    print(str.strip(message))



main()

输出为 在此处输入消息。尤塞夫 您想加密还是解密?加密 'J''F''V''Z''3'

  
    
      

问题是^^^我不能在输出中包含那些“''。必须是JFVZ3

    
  

1 个答案:

答案 0 :(得分:1)

只需删除“表示形式”转换repr()

def code_encrypt(x, y, z):
    message = ''
    for i in (z):
         for j in range(len(x)):
             if i == x[j]:
                message = message + y[j]
    print(message)