morse_code
Package for converting from and to morse code.
Morse Code Decoder/Encoder
A very basic application to convert plain text into morse code and vice versa
This application expects a user to first choose to decode or encode morse code. Based upon the user's choice user then enters either morse code in morse characters seperated by commas or regular text in alphabet letters.
The output is either decoded morse code (output = text in latin) or encoded text (output = morse code).
Features
- Converts text to morse code.
- Converts morse code to text.
Tech
This application uses three functions:
def main(): Prompts user to enter either 1 or 2, where 1 is for encoding text into morse code and 2 is for decoding morse code into text. The user's option value is validated and the result is printed out on the terminal based on the user's choice. return: Encoded text into morse code or Decoded morse code into text.
def encode(user_input): Contains a dictionary of alphabet to morse code. User input is looped through and compared to dictionary keys. Individual values are concatenated into a variable which is printed to the terminal. parameter: user input return: Morse code.
def decode(user_input): Contains a dictionary of morse code to alphabet. User input in morse code is made into a list which is then looped through and compared to dictionary keys. Individual values are concatenated into a variable which is printed to the terminal. :parameter: user_input :return: Morse code translation - text in latin alphabet.
Installation
No installation needed.
License
Free to use application.
1"""Package for converting from and to morse code. 2 3.. include:: README.md 4""" 5# importing functions 6from .morse_func import decode, encode 7 8 9# main function encodes text into morse code 10# or decodes morse code into text 11def main(): 12 """Translate from or into morse code. 13 14 Prompts user to enter either 1 or 2, where 1 is for encoding text 15 into morse code and 2 is for decoding morse code into text. 16 The user's option value is validated and the result is printed out on 17 the terminal based on the user's choice. 18 :return: Encoded text into morse code or Decoded morse code into text. 19 """ 20 # user chooses to encode or decode morse code 21 user_option = (input("For encoding type (1), for decoding type (2): ")) 22 # If the user inputs 1, the encode function gets executed and printed out 23 if user_option == "1": 24 print(encode(input("Please enter your text: "))) 25 # If the user inputs 2, the decode function gets executed and printed out 26 elif user_option == "2": 27 print(decode(input("Please enter morse code: "))) 28 # If the user inputs invalid entry 29 else: 30 print("Invalid input! Please enter 1 for encoding or 2 for decoding.") 31 32 33if __name__ == "__main__": 34 main()
12def main(): 13 """Translate from or into morse code. 14 15 Prompts user to enter either 1 or 2, where 1 is for encoding text 16 into morse code and 2 is for decoding morse code into text. 17 The user's option value is validated and the result is printed out on 18 the terminal based on the user's choice. 19 :return: Encoded text into morse code or Decoded morse code into text. 20 """ 21 # user chooses to encode or decode morse code 22 user_option = (input("For encoding type (1), for decoding type (2): ")) 23 # If the user inputs 1, the encode function gets executed and printed out 24 if user_option == "1": 25 print(encode(input("Please enter your text: "))) 26 # If the user inputs 2, the decode function gets executed and printed out 27 elif user_option == "2": 28 print(decode(input("Please enter morse code: "))) 29 # If the user inputs invalid entry 30 else: 31 print("Invalid input! Please enter 1 for encoding or 2 for decoding.")
Translate from or into morse code.
Prompts user to enter either 1 or 2, where 1 is for encoding text into morse code and 2 is for decoding morse code into text. The user's option value is validated and the result is printed out on the terminal based on the user's choice.
Returns
Encoded text into morse code or Decoded morse code into text.