Last active
October 2, 2017 11:49
-
-
Save JaDogg/afac0ab98e7e6bbeb3c2fb616daca0c6 to your computer and use it in GitHub Desktop.
Python 3 Dictionary Usage to Calculate Morse Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See Python 3 Dictionary Usage for related python tutorial.