MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

src/gamesbyexample/morsecode.py:27–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25
26
27def main():
28 print('Morse Code, by Al Sweigart al@inventwithpython.com')
29 print()
30
31 while True:
32 print('Are you going to enter (E)nglish or (M)orse code?')
33 response = input('> ').upper()
34 # Note that you DON'T want "response == 'E' or 'M'" here:
35 if response == 'E' or response == 'M':
36 break
37
38 if response == 'E':
39 print('Enter English text:')
40 english = input('> ').upper()
41 print('Morse code:')
42 morse = englishToMorse(english)
43 print(morse)
44 try:
45 pyperclip.copy(morse)
46 print('(Morse copied to clipboard.)')
47 except:
48 pass
49 elif response == 'M':
50 print('Enter Morse code (use spaces after each code letter):')
51 morse = input('> ')
52 print('English:')
53 english = morseToEnglish(morse)
54 print(english)
55
56 try:
57 pyperclip.copy(english)
58 print('(English text copied to clipboard.)')
59 except:
60 pass # If pyperclip is not installed, do nothing.
61
62
63def englishToMorse(message):

Callers 1

morsecode.pyFile · 0.70

Calls 2

englishToMorseFunction · 0.85
morseToEnglishFunction · 0.85

Tested by

no test coverage detected