ZIP indir
0
main
1 dal
git@carbon4code.com:ahmet/Python-for-Data-Science.git
Ahmet Kerem Piscine Final
10 commit
sos.py 1.1 KB
import sys

NESTED_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": "--.. ",
    "0": "----- ", "1": ".---- ", "2": "..--- ", "3": "...-- ",
    "4": "....- ", "5": "..... ", "6": "-.... ", "7": "--... ",
    "8": "---.. ", "9": "----. ",
}


def main() -> None:
    """Encode the given string into Morse code."""
    try:
        if len(sys.argv) != 2:
            raise AssertionError("the arguments are bad")
        text = sys.argv[1].upper()
        if not all(c in NESTED_MORSE for c in text):
            raise AssertionError("the arguments are bad")
        print("".join(NESTED_MORSE[c] for c in text).strip())
    except AssertionError as error:
        print(f"AssertionError: {error}")


if __name__ == "__main__":
    main()