0% found this document useful (0 votes)
38 views9 pages

Morse Code Cnverter - PWP

Uploaded by

Pranav Ghom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views9 pages

Morse Code Cnverter - PWP

Uploaded by

Pranav Ghom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Morse code translator

Morse code translator using python

Programming with Python (22520)


INDEX

Sr. No Topic Page no.


1 Rationale

2 Aims/Benefits of the Micro-Project

3 Course Outcomes Addressed

4 Objective

5 Resource Used

6 Code of python application

7 Output

8 Working of Application

9 Conclusion

10
Morse code translator

1.0 Rationale:-
The provided Python program is a simple Morse code translator that
converts text to Morse code and vice versa. It utilizes a dictionary to map
characters to their Morse code equivalents and vice versa. The text_to_morse
function takes a string of text as input and converts it to Morse code, while
the morse_to_text function takes Morse code as input and converts it back to
text. The program includes a loop that continuously prompts the user for
input until the user types "exit" to quit. Depending on whether the input
contains Morse code characters or regular text characters, it decides which
translation function to use and prints the result accordingly.

2.0 Aims/Benefits of the Micro-Project:-


Aim:- The aim of the provided Python program is to create a simple
Morse code translator. It allows users to convert text into Morse code and
vice versa. The program achieves this by defining a dictionary that maps
characters to their corresponding Morse code representations and vice
versa. It then provides two functions: text_to_morse for converting text to
Morse code and morse_to_text for converting Morse code back to text. The
program continuously prompts the user for input, allowing them to either
enter text or Morse code, and then displays the translated result. The loop
continues until the user decides to exit the program. Overall, the aim is to
provide a user-friendly tool for Morse code translation.

Benefits:-
1. Emergency Situations
2. Historical Significance
3. Education
4. Communication in Noise-sensitive Environments
5. Fun and Hobbyist Projects
3.0 Course Outcomes Addressed:-
The provided Morse code translator program addresses several course
outcomes related to programming, communication systems, and problem-
solving. Firstly, it demonstrates proficiency in Python programming by
utilizing concepts such as dictionaries, loops, conditional statements, and
functions to implement the translation logic efficiently. This aligns with
course outcomes focused on programming skills development and problem-
solving abilities.
Secondly, the program incorporates an understanding of communication
systems, particularly Morse code encoding and decoding principles. By
mapping characters to their corresponding Morse code representations and
vice versa using a dictionary, the program showcases comprehension of
encoding techniques and data representation, which is pertinent to courses
covering communication theory or data encoding.

4.0 Objective:-
The objective of the provided Morse code translator program is to develop a
functional tool that enables users to seamlessly convert text to Morse code
and vice versa. Through the implementation of Python programming
techniques, the program aims to fulfill several objectives:
Firstly, it seeks to foster a deeper understanding of programming concepts
such as dictionaries, loops, conditional statements, and functions by
applying them in a practical context. By translating user input into Morse
code or text, the program reinforces fundamental programming skills and
encourages hands-on learning.
5.0 Resource Used:-

Sr. Name of Resource Broad Specification Quantity


No.
1 Computer system i5 Processor | 8GB Ram ---
2 Operation system Windows 11 ---
3 Development software Python IDE ---

6.0 Code of python application:-


MORSE_CODE_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': '--..',
'1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...',
'8': '---..', '9': '----.', '0': '-----',
'.': '.-.-.-', ',': '--..--', '?': '..--..', '/': '-..-.', '@': '.--.-.', ' ': '/'
}

def text_to_morse(text):
morse_code = ''
for char in text.upper():
if char in MORSE_CODE_DICT:
morse_code += MORSE_CODE_DICT[char] + ' '
else:
morse_code += char + ' '
return morse_code

def morse_to_text(morse_code):
text = ''
morse_code += ' '
inv_morse_dict = {v: k for k, v in MORSE_CODE_DICT.items()}
morse_char = ''
for char in morse_code:
if char != ' ':
morse_char += char
else:
if morse_char in inv_morse_dict:
text += inv_morse_dict[morse_char]
else:
text += ' '
morse_char = ''
return text.lower()

while True:
# Get input from the user
input_text = input("Enter text or Morse code (type 'exit' to quit): ")

# Check if user wants to exit


if input_text.lower() == 'exit':
print("Exiting...")
break

# Check if input is Morse code or text


if any(char in input_text for char in MORSE_CODE_DICT.values()):
print("Morse Code to Text:", morse_to_text(input_text))
else:
print("Text to Morse Code:", text_to_morse(input_text))

7.0 Output :-
8.0 Working of Application:-
The Morse code translator application functions by seamlessly converting
text to Morse code and vice versa through an intuitive user interface. Upon
execution, the program prompts the user to input either text or Morse code,
allowing for versatile communication in either format.
When the user enters text, the program utilizes a predefined dictionary that
maps each alphanumeric character to its corresponding Morse code
representation. By iterating through the input text and accessing the
dictionary, the program constructs the Morse code equivalent, appending
each Morse code sequence to form the complete translation. This process
ensures accurate encoding of the input text into Morse code.
Conclusion

In conclusion, the Morse code translator program exemplifies the fusion of


programming proficiency, communication systems understanding, and
problem-solving acumen to create a versatile and functional tool. Through
its implementation in Python, the program enables users to effortlessly
translate text to Morse code and vice versa, fostering a deeper appreciation
for both programming concepts and Morse code communication principles.
By utilizing dictionaries, loops, conditional statements, and functions, the
program demonstrates mastery of fundamental programming techniques
while addressing the complexities of Morse code encoding and decoding. Its
intuitive user interface and error handling mechanisms ensure a seamless
and reliable translation process, accommodating diverse user inputs and
scenarios.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy