Python Forum
morse code assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
morse code assignment
#1
Hello again and as always thank you for your continued help.I have reached out to the instructor but have not gotten any reply.
here is my issue. I have added all steps because i feel they all go together. I will post my code for step one
Step 1

In this step, you'll set up the logic to convert letters to Morse code.

Create an application that asks the user to enter an upper case letter.
Use an if-elif construct to determine which letter was entered and store the appropriate Morse code string in a variable. If there is no match, set the variable to "Unknown".
As an example, the Morse code for the letter 'S' is represented using a string of three periods, "...", for dot dot dot.
The Morse code for "O" is represented by three hyphens, "---", for dash dash dash.
Display the variable.
Save the program as step_1.py.
intro='''
This program will convert your text into morse code.
'''
print (intro)
Letter = input("Please enter an upper case letter or series of letters:")
if Letter == "A":
    print(".-")
elif Letter == "B":
    print("-...")
elif Letter == "C":
    print("-.-.")
elif Letter == "D":
    print("-..")

#list of Morse code to build program on
CODE = {'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': '--..',
        
        '0': '-----',  '1': '.----',  '2': '..---',
        '3': '...--',  '4': '....-',  '5': '.....',
        '6': '-....',  '7': '--...',  '8': '---..',    
        '9': '----.' 
        }
Step 2

In this step, you'll create a function to do the translation. This will make it easy to reuse the code for the if-elif logic without having to make lots of copies later on.

Copy step_1.py into a new program and call it step_2.py
Create a function named text_to_morse. The function should have one parameter, which contains the letter to be translated. Note that the function should be located at the top of the program just underneath the header comments.
Move just the if-elif code into the function, remembering to indent it. But, do not include the input statement or the print statement.
Add a return statement to the function that returns the variable containing the result.
After the input statement, add a call to the function using the input variable as the argument to the function.
Store the value returned by the function in a variable and display it.

I am strugling with step 2 i can not figure outwhat function to use or how to get my if and elif into it
Reply


Messages In This Thread
morse code assignment - by raymond2688 - Jul-28-2019, 07:32 PM
RE: morse code assignment - by raymond2688 - Jul-28-2019, 09:38 PM
RE: morse code assignment - by ichabod801 - Jul-28-2019, 09:52 PM
RE: morse code assignment - by raymond2688 - Jul-28-2019, 09:57 PM
RE: morse code assignment - by ichabod801 - Jul-28-2019, 10:51 PM
RE: morse code assignment - by raymond2688 - Jul-29-2019, 12:37 PM
RE: morse code assignment - by ichabod801 - Jul-29-2019, 02:00 PM
RE: morse code assignment - by raymond2688 - Jul-29-2019, 05:02 PM
RE: morse code assignment - by jefsummers - Jul-29-2019, 05:20 PM
RE: morse code assignment - by ichabod801 - Jul-29-2019, 06:13 PM
RE: morse code assignment - by raymond2688 - Jul-29-2019, 06:20 PM
RE: morse code assignment - by raymond2688 - Jul-29-2019, 07:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Morse Assignment Cambridge 3 2,570 Feb-02-2021, 02:40 AM
Last Post: Larz60+
  Write pseudo code for a class assignment Scrimshot 3 3,550 May-07-2019, 05:38 PM
Last Post: Scrimshot
  Need some help with a bit of code for an assignment. JackMercer50 1 2,364 Feb-09-2019, 04:13 PM
Last Post: stullis
  Need help with lists to continue my assignment code tinabina22 9 10,774 Oct-12-2016, 12:20 AM
Last Post: Yoriz
  [split] Need help with lists to continue my assignment code cylandur 7 9,774 Oct-11-2016, 03:11 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020