본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 50

반응형

Q>

"Where does a wise man hide a leaf? In the forest. But what does he do if there is no forest? ... He grows a forest to hide it in."
-- Gilbert Keith Chesterton

("나는 무엇을해야할지 모르지만 무엇을해야할지 모른다." - 길버트 키스 체스터 톤)

Ever tried to send a secret message to someone without using the postal service?

(우편 서비스를 사용하지 않고 누군가에게 비밀 메시지를 보내려고하십니까?)

You could use newspapers to tell your secret.

(당신은 당신의 비밀을 말하기 위해 신문을 사용할 수 있습니다.)

Even if someone finds your message, it's easy to brush them off as paranoid and as a conspiracy theorist.

(누군가가 당신의 메시지를 발견하더라도, 편집증 및 음모 이론가로서 그들을 털어내는 것은 쉽습니다.)

One of the simplest ways to hide a secret message is to use capital letters.

(비밀 메시지를 숨기는 가장 간단한 방법 중 하나는 대문자를 사용하는 것입니다.)

Let's find some of these secret messages.

(이 비밀 메시지를 찾아 보겠습니다.)

You are given a chunk of text.

(당신은 텍스트 덩어리를받습니다.)

Gather all capital letters in one word in the order that they appear in the text.

(한 단어의 모든 대문자를 텍스트에 나타나는 순서대로 모으십시오.)

For example: text = "How are you? Eh, ok. Low or Lower? Ohhh.", if we collect all of the capital letters, we get the message "HELLO".

(예를 들면 다음과 같습니다. text = "How are you? 어, ok, Low or Lower? Ohhh."우리가 대문자를 모두 모으면 "HELLO"라는 메시지가 나타납니다.)

 

Input: A text as a string (unicode).(문자열 (유니 코드)로 된 텍스트.)

 

Output: The secret message as a string or an empty string.(문자열 또는 빈 문자열로 된 비밀 메시지입니다.)

 

Example:

find_message("How are you? Eh, ok. Low or Lower? Ohhh.") == "HELLO"
find_message("hello world!") == ""

 

How it is used: This is a simple exercise in working with strings: iterate, recognize and concatenate.

(이것은 문자열 작업에 대한 간단한 연습 : 반복, 인식 및 연결.)

 

Precondition: 0 < len(text) ≤ 1000
all(ch in string.printable for ch in text)

 

A>

def find_message(text: str) -> str:
    """Find a secret message"""
    # 대문자를 가져오게 하면 된다
    # isupper : 문자가 대문자인지 확인 메소드
    # filter : 특정 만족하는 문자를 가져온다
    return ''.join(filter(str.isupper, text))

if __name__ == '__main__':
    print('Example:')
    print(find_message("How are you? Eh, ok. Low or Lower? Ohhh."))

    # These "asserts" using only for self-checking and not necessary for auto-testing
    assert find_message("How are you? Eh, ok. Low or Lower? Ohhh.") == "HELLO", "hello"
    assert find_message("hello world!") == "", "Nothing"
    assert find_message("HELLO WORLD!!!") == "HELLOWORLD", "Capitals"
    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

 

O>

Example:
HELLO
Coding complete? Click 'Check' to review your tests and earn cool rewards!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 52  (0) 2019.06.11
Python Learn the basics Quiz 51  (0) 2019.06.11
Python Learn the basics Quiz 49  (0) 2019.06.10
Python Learn the basics Quiz 48  (0) 2019.06.10
Python Learn the basics Quiz 47  (0) 2019.06.10