Skip to content

Commit

Permalink
extra credit for hw
Browse files Browse the repository at this point in the history
  • Loading branch information
adik1025 committed Oct 10, 2024
1 parent 7b7359f commit 2479b26
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions _notebooks/2024-10-9-3_6.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,43 @@
"print(leapyear(2000)) #call the function with the year 2000\n",
"print(leapyear(2001)) #call the function with the year 2004"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Extra Credit: Morse Code Encoder"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"char_to_dots = {\n",
" 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',\n",
" 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',\n",
" 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',\n",
" 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',\n",
" 'Y': '-.--', 'Z': '--..', ' ': ' ', '0': '-----',\n",
" '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....',\n",
" '6': '-....', '7': '--...', '8': '---..', '9': '----.',\n",
" '&': '.-...', \"'\": '.----.', '@': '.--.-.', ')': '-.--.-', '(': '-.--.',\n",
" ':': '---...', ',': '--..--', '=': '-...-', '!': '-.-.--', '.': '.-.-.-',\n",
" '-': '-....-', '+': '.-.-.', '\"': '.-..-.', '?': '..--..', '/': '-..-.'\n",
"}\n",
"def encode_morse(message):\n",
" if len(message) == 0:\n",
" return \"Message is too short\"\n",
"\tresult=\"\"\n",
"\tfor i in message.upper():\n",
"\t\tresult += char_to_dots[i]+\" \"\n",
"\treturn result[0:-1]\n",
"\n",
"\n",
"encode_morse(\"Howdy\") #call the function with the string \"Howdy\""
]
}
],
"metadata": {
Expand Down

0 comments on commit 2479b26

Please sign in to comment.