Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
783 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 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...