Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 I always get 'None' returned. Confused. What did I miss?
#1
import random


# Morse Code string translator
# delimited with spaces for characters, and / for words
# format example "HELLO WORLD": .... . .-.. .-.. --- / .-- --- .-. .-.. -..
def untranslate_morse_code_string(code_string):

    InvertmorseAlphabet = {

        " ": "/", "A": ".-", "C": "-.-.", "B": "-...", "E": ".", "D": "-..",
        "G": "--.", "F": "..-.", "I": "..", "H": "....", "K": "-.-", "J": ".---",
        "M":  "--", "L": ".-..","O": "---", "N": "-.", "Q": "--.-", "P": ".--.",
        "S": "...", "R": ".-.", "U": "..-", "T": "-", "W": ".--", "V": "...-",
        "Y": "-.--", "X": "-..-", "Z": "--..",
        "1": ".----", "2": "..---", "3": "...--", "4": "....-", "5": ".....",
        "6": "-....", "7": "--...", "8": "---..", "9": "----.", "0": "-----"
    }
    print (InvertmorseAlphabet)
    print (code_string)


def translate_morse_code_string(code_string):

    morseAlphabet = {
        "/": " ", ".-": "A", "-.-.": "C", "-...": "B", ".": "E", "-..": "D",
        "--.": "G", "..-.": "F", "..": "I", "....": "H", "-.-": "K", ".---": "J",
        "--":  "M", ".-..": "L","---": "O", "-.": "N", "--.-": "Q", ".--.": "P",
        "...": "S", ".-.": "R", "..-": "U", "-": "T", ".--": "W", "...-": "V",
        "-.--": "Y", "-..-": "X", "--..": "Z",
        ".----": "1", "..---": "2", "...--": "3", "....-": "4", ".....": "5",
        "-....": "6", "--...": "7", "---..": "8", "----.": "9", "-----": "0"
    }



Consonant = [ 'B', 'C', 'D', 'F',  'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P',  'Q', 'W', 'X', 'Z']
Vowel = ['A', 'E', 'I', 'O', 'U', 'Y'] # Sometimes y and w. Need more vowels
Number = [ '0', '1', '2', '3',  '4', '5', '6', '7', '8', '9' ]
#
# This below works
#
input_msg=random.choice(Vowel)+random.choice(Number)+random.choice(Consonant)
string_len=len(input_msg)
print(input_msg,string_len)
#
# End of this works
#
x=input_msg[2]
character_output = untranslate_morse_code_string(x)
print (x, character_output)
#
#What happens if I force a particular letter
#
x='G'
character_output = untranslate_morse_code_string(x)
print (x, character_output)
#
#What happens if I use the translate on a particular code
#
x="..."
character_output = translate_morse_code_string(x)
print (x, character_output)
Quote
#2
You need a return statement. If you don't explicitly return something with a return statement, None is returned by default. Your functions don't seem to be doing anything, so I'm not sure exactly what they should return.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
Duh!

This is what happens when you copy and modify a routine.

I left off all the code. I wasn't paying attention to what I was doing and was overtired.

Thanks. It works fine with the rest of the code in it.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to use a returned value? t4keheart 12 243 Jan-16-2020, 06:54 AM
Last Post: perfringo
  Not all data returned from sys.argv ecdhyne 2 318 Sep-05-2019, 08:27 PM
Last Post: buran
  sys.path miss dist-packages in a virtual env. chomwitt 2 319 May-23-2019, 08:08 PM
Last Post: chomwitt
  Confused by order of operations ward 4 454 Jan-22-2019, 08:53 PM
Last Post: Larz60+
  Confused by this modulo equation VikramSuh 3 604 Sep-05-2018, 12:43 PM
Last Post: VikramSuh
  I am new to python , i am confused with this syntax , please help aankrose 3 638 Aug-03-2018, 06:49 PM
Last Post: aankrose
  Still confused about how passing arguments works RedSkeleton007 3 855 Apr-25-2018, 11:01 AM
Last Post: snippsat
  understanding lists....I'm very confused mepyyeti 7 1,448 Dec-23-2017, 02:06 PM
Last Post: mpd
  Confused by {} in Python code Oliver 6 1,176 Dec-03-2017, 05:15 PM
Last Post: Oliver
  how to do comparison for the value returned by os.system jash 2 1,074 Nov-11-2017, 11:09 AM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)