Python Forum
morse code assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
morse code assignment
#7
The error you are getting in step 2 is because of the else clause, where you print 'Unknown Text'. You don't assign anything to code in that case. So when you try to return code on line 12, you haven't created anything named code, and Python gets confused. In that case I would set code to a dummy value, like an empty string or '???'.

One step three, you have three different things named code: the function on line 1, the loop variable on line 13, and the morse code value returned on line 15. Each time you assign the name code to something, you lose what it was assigned to before. So all three of those things need different names.

Note that the for variable should not be looping over letter. The instructions say to loop four times. You do that by looping over range(4). You also need a colon at the end of the for loop on line 13, and you need to indent each line of code that should be repeated after the for statement.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
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,540 Feb-02-2021, 02:40 AM
Last Post: Larz60+
  Write pseudo code for a class assignment Scrimshot 3 3,537 May-07-2019, 05:38 PM
Last Post: Scrimshot
  Need some help with a bit of code for an assignment. JackMercer50 1 2,348 Feb-09-2019, 04:13 PM
Last Post: stullis
  Need help with lists to continue my assignment code tinabina22 9 10,687 Oct-12-2016, 12:20 AM
Last Post: Yoriz
  [split] Need help with lists to continue my assignment code cylandur 7 9,721 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