Last active
June 4, 2017 04:06
-
-
Save nattybear/436e4f0bbabb8e20d652039e3cbd28dc to your computer and use it in GitHub Desktop.
점프투파이썬 연습문제 - 모스 부호
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
| # 모스 부호를 키와 값의 쌍인 | |
| # 딕셔너리로 저장한다. | |
| dic = { '.-' : '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' } | |
| # 사용자 입력을 받는다. | |
| s = input() | |
| # 문장을 띄어쓰기 두칸으로 구분하여 | |
| # 단어들을 담은 리스트로 쪼갠다. | |
| words = s.split(' ') | |
| # 단어들을 담은 리스트를 대상으로 | |
| # 반복문을 돈다. | |
| for i in words: | |
| # 띄어쓰기 한칸을 구분하여 | |
| # 글자들을 담은 리스트를 만든다. | |
| chars = i.split() | |
| # 글자들을 대상으로 반복문을 돈다. | |
| for j in chars: | |
| # 딕셔너리를 이용해서 | |
| # 모스부호 키에 해당하는 | |
| # 알파벳을 이어서 출력한다. | |
| print(dic[j], end='') | |
| # 단어와 단어는 띄어쓰기 한칸으로 출력한다. | |
| print('', end=' ') | |
| # 모든 출력이 끝나면 개행을 한다. | |
| print() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
모스 부호 문제는 키와 값의 쌍을 이용한 딕셔너리로 접근하자!
키로 한다.값으로 하면 출력하기 편하다!입력 및 출력 결과
입력
.... . ... .-.. . . .--. ... . .- .-. .-.. -.--출력
HE SLEEPS EARLY