Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

python-3.x - 我似乎找不到导致故障的错误[关闭](I cannot seem to find the error that is causing the malfunction [closed])

My Morse Code Encryption function doesn't work, how can I identify anything that could be causing this?

(我的摩尔斯电码加密功能不起作用,如何识别可能导致这种情况的任何东西?)

When implemented into my main program, it will work up to the input field for users to enter a message to be encrypted, but then it fails once I press enter.

(当在我的主程序中实现后,它将在输入字段中起作用,以便用户输入要加密的消息,但是一旦按Enter键,它就会失败。)

The error is that it tells me that Run Encryption is invalid, but the choice Run Encryption is properly coded to access the encrypt() function.

(错误是,它告诉我“运行加密”无效,但是对“运行加密”选项进行了正确的编码以访问crypto()函数。)

C:UsersmatloPycharmProjectsPythonLearningvenvScriptspython.exe C:/Users/matlo/PycharmProjects/PythonLearning/ProgramwBasics.py
Hello, World! 
 ----------------------------------------
What is your name?:Matt

Hello! Matt 
 ----------------------------------------
What do you want to do?:Run Encryption

Message to be Encrypted: HELLO

'Run Encryption'is invalid.

Maybe try:

Open Chrome

Date and Time

Calculator

Times Table

Run Encryption

Terminate

What do you want to do?:

Code:

(码:)

CODE = {' ': '_',
        "'": '.----.',
        '(': '-.--.-',
        ')': '-.--.-',
        ',': '--..--',
        '-': '-....-',
        '.': '.-.-.-',
        '/': '-..-.',
        '0': '-----',
        '1': '.----',
        '2': '..---',
        '3': '...--',
        '4': '....-',
        '5': '.....',
        '6': '-....',
        '7': '--...',
        '8': '---..',
        '9': '----.',
        ':': '---...',
        ';': '-.-.-.',
        '?': '..--..',
        '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': '--..',
        '_': '..--.-'}


def encrypt():
    sentence = input("Message to be Encrypted: ")
    encoded_sentence = ""
    for character in sentence:
        encoded_sentence += CODE[character] + " "
    return encoded_sentence
  ask by Matthew Lodge translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

似乎工作正常,您只需要在字典中添加小写字母,或根据需要将句子转换为所有大写字母即可。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...