Python Forum
I always get 'None' returned. Confused. What did I miss?
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)
Reply


Messages In This Thread
I always get 'None' returned. Confused. What did I miss? - by jpezz - Apr-07-2019, 01:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to access values returned from inquirer cspower 6 804 Dec-26-2023, 09:34 PM
Last Post: cspower
  String int confused janeik 7 1,076 Aug-02-2023, 01:26 AM
Last Post: deanhystad
  I am confused with the key and value thing james1019 3 966 Feb-22-2023, 10:43 PM
Last Post: deanhystad
  SQLAlchemy Object Missing when Null is returned Personne 1 1,745 Feb-19-2022, 02:50 AM
Last Post: Larz60+
  Pandas confused DPaul 6 2,559 Sep-19-2021, 06:45 AM
Last Post: DPaul
  is and '==' i'm confused hshivaraj 6 2,710 Sep-15-2021, 09:45 AM
Last Post: snippsat
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 3,635 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 3,005 Sep-06-2021, 07:24 PM
Last Post: jpncsu
  Confused with 'flags' tester_V 10 4,913 Apr-12-2021, 03:03 AM
Last Post: tester_V
  Simple Tic Tac Toe but I'm confused Izith 1 2,192 Sep-26-2020, 04:42 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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