Skip to content

Instantly share code, notes, and snippets.

@JaDogg
Last active Oct 2, 2017
Embed
What would you like to do?
Python 3 Dictionary Usage to Calculate Morse Code
#!/usr/bin/env python3
# http://pandabunnytech.com
morse = {"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": "--.."}
phrase = "HELLO WORLD"
print(phrase)
for word in phrase.split():
for ch in word:
print(morse[ch], end=' ')
print(' ' * 7, end='')
print()
@JaDogg
Copy link
Author

JaDogg commented Oct 2, 2017

See Python 3 Dictionary Usage for related python tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment