Skip to main content
 首页 » 编程设计

python之如何在 Python 中搜索嵌套列表网格并给出字母坐标

2025年05月04日15EasonJim

<分区>

我是 python 的新手,为实现这一目标付出了很多努力。 这是我的任务:

The Six-Letter Cipher is a method of encoding a secret message that involves both substitution and transposition. The encryption starts by randomly filling a 6  6 grid with the alphabet letters from A to Z and the digits from 0 to 9 (36 symbols in total). This grid must be known to both the sender and receiver of the message. The rows and columns of the grid are labelled with the letters A, B, C, D, E, F.

Write a Python program that implements the six-letter cipher method. Your program should: 1. Create a 6x6 grid and fill it randomly with letters and numbers as described in the first paragraph, then prompt the user to enter a secret message. 2. Display the 6x6 grid and the generated ciphertext, after the user enters the secret message. 3. Prompt the user to enter the ciphertext to display the original message. It is OK to ask the user to separate every two letters of the ciphertext with a space or comma.

我遇到的问题是如何在嵌套列表中搜索已输入的随机放置的字母并给出坐标。坐标也不会以数字形式给出,即 0,1,而不是字母,即 A,B 一旦我了解了如何使用这个嵌套列表,我想我可以管理编码和解码。

到目前为止,这是我的代码:

grid = [["Z","9","G","Q","T","3"], 
    ["Y","8","F","P","S","2"], 
    ["X","7","E","O","R","1"], 
    ["W","6","D","N","M","0"], 
    ["V","5","C","L","K","U"], 
    ["J","4","B","I","H","A"]] 
 
def main(): 
    print("Welcome to the sixth cipher") 
    print("Would you like to (E)Encode or (D)Decode a message?") 
    operation = input() 
 
    if(operation == "E"): 
        encodecipher() 
    elif(operation == "D"): 
        decodecipher() 
    else: 
        print("Sorry, input not recognised") 
 
def encodecipher(): 
    print("Please enter a message to encode:") 
    messagetoencode = input() 
 
 
 
def decodecipher(): 
    print("Decode Test") 
    rowcolumn() 
 
 
def rowcolumn(): 
    pass 
 
main()