Hi Bartleby, by using this code :  def print_intro():     print("Welcome to Wolmorse")     print("This program encodes and decodes Morse code.") def get_input():     cont = True     while cont:         ch1 = input("Would you like to encode (e) or decode (d): ")         if ch1 in 'de':             ch2 = input("Would you like to read from a file (f) or console (c): ")             if ch1 == 'd' and ch2 == 'c':                 msg = input("What message would you like to decode: ")                 print(decode(msg))             elif ch1 == 'e' and ch2 == 'c':                 msg = input("What message would you like to encode: ")                 print(encode(msg))             elif ch1 == 'd' and ch2 == 'f':                 file_name = input("Enter a filename: ")                 if check_file_exists(file_name):                     msg = process_lines(file_name, 'r')                     result = decode(msg)                     write_lines(result)                 else:                     print("Invalid Filename")             elif ch1 == 'e' and ch2 == 'f':                 file_name = input("Enter a filename: ")                 if check_file_exists(file_name):                     msg = process_lines(file_name, 'r')                     result = encode(msg)                     write_lines(result)                 else:                     print("Invalid Filename")             ch_cont = input("Would you like to encode/decode another message: ")             if ch_cont == 'n':                 cont = False                 print("Thanks for using the program, Goodbye. ") def encode(message):     encode_dict = {'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': '--..', ' ': '.....'}     encoded = ' '.join(encode_dict[i] for i in message.upper())     return encoded def decode(message):     encode_dict = {'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': '--..', ' ': '.....'}     decode_dict = {v: k for k, v in encode_dict.items()}     decoded = ''.join(decode_dict[i] for i in message.split())     return decoded def process_lines(filename, mode):     with open(filename, 'r') as f:         msg = f.read()         return msg def write_lines(lines):     with open('results.txt', 'w') as f:         f.writelines(lines)         print("Output written to results.txt") def check_file_exists(filename):     from os.path import exists     file_exists = exists(filename)     return file_exists def main():     print_intro()     get_input() # Call main function main() I need to furthermore to continue this and I need some help understanding it,

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hi Bartleby, by using this code : 

def print_intro():
    print("Welcome to Wolmorse")
    print("This program encodes and decodes Morse code.")


def get_input():
    cont = True
    while cont:
        ch1 = input("Would you like to encode (e) or decode (d): ")
        if ch1 in 'de':
            ch2 = input("Would you like to read from a file (f) or console (c): ")
            if ch1 == 'd' and ch2 == 'c':
                msg = input("What message would you like to decode: ")
                print(decode(msg))
            elif ch1 == 'e' and ch2 == 'c':
                msg = input("What message would you like to encode: ")
                print(encode(msg))
            elif ch1 == 'd' and ch2 == 'f':
                file_name = input("Enter a filename: ")
                if check_file_exists(file_name):
                    msg = process_lines(file_name, 'r')
                    result = decode(msg)
                    write_lines(result)
                else:
                    print("Invalid Filename")
            elif ch1 == 'e' and ch2 == 'f':
                file_name = input("Enter a filename: ")
                if check_file_exists(file_name):
                    msg = process_lines(file_name, 'r')
                    result = encode(msg)
                    write_lines(result)
                else:
                    print("Invalid Filename")

            ch_cont = input("Would you like to encode/decode another message: ")
            if ch_cont == 'n':
                cont = False
                print("Thanks for using the program, Goodbye. ")


def encode(message):
    encode_dict = {'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': '--..', ' ': '.....'}
    encoded = ' '.join(encode_dict[i] for i in message.upper())
    return encoded


def decode(message):
    encode_dict = {'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': '--..', ' ': '.....'}
    decode_dict = {v: k for k, v in encode_dict.items()}
    decoded = ''.join(decode_dict[i] for i in message.split())
    return decoded


def process_lines(filename, mode):
    with open(filename, 'r') as f:
        msg = f.read()
        return msg


def write_lines(lines):
    with open('results.txt', 'w') as f:
        f.writelines(lines)
        print("Output written to results.txt")


def check_file_exists(filename):
    from os.path import exists
    file_exists = exists(filename)
    return file_exists


def main():
    print_intro()
    get_input()


# Call main function
main()

I need to furthermore to continue this and I need some help understanding it, thank you 

Introduction:
The Morse Code encoder/decoder that you've developed works well, however, one major
drawback is that it's only capable of encoding/decoding a single message at a time. Therefore,
your task for this challenge will be to attempt to resolve this issue by implementing file
reading/writing capabilities so that multiple messages can be encoded/decoded in one go.
To do this, you will need to implement the process_lines (), write_lines (),
check_file_exists and get_filename_input () functions.
The first function process_lines () should take two parameters, the filename from which
messages should be read and the mode of operation (encoding/decoding). It should process the
lines in the file one by one, returning a list of encoded/decoded messages.
A file has been added to the assessment page on Canvas, morse_input.txt, that includes
a series of plain text strings, which you can use to test your function.
Example Implementation:
>>> process_lines ("morse_input.txt", "e")
['....
The second function check_file_exists () should take a single parameter, a filename
and return a Boolean value (True/False) depending upon whether the file exists within the
current folder. There are several ways that you can achieve this, for example using exception
handling logic or through the built-in OS module included with Python.
Example Implementation:
>>> check_file_exists ("morse_input.txt")
True
Transcribed Image Text:Introduction: The Morse Code encoder/decoder that you've developed works well, however, one major drawback is that it's only capable of encoding/decoding a single message at a time. Therefore, your task for this challenge will be to attempt to resolve this issue by implementing file reading/writing capabilities so that multiple messages can be encoded/decoded in one go. To do this, you will need to implement the process_lines (), write_lines (), check_file_exists and get_filename_input () functions. The first function process_lines () should take two parameters, the filename from which messages should be read and the mode of operation (encoding/decoding). It should process the lines in the file one by one, returning a list of encoded/decoded messages. A file has been added to the assessment page on Canvas, morse_input.txt, that includes a series of plain text strings, which you can use to test your function. Example Implementation: >>> process_lines ("morse_input.txt", "e") ['.... The second function check_file_exists () should take a single parameter, a filename and return a Boolean value (True/False) depending upon whether the file exists within the current folder. There are several ways that you can achieve this, for example using exception handling logic or through the built-in OS module included with Python. Example Implementation: >>> check_file_exists ("morse_input.txt") True
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY