본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 55

반응형

Q>

You are given a string where you have to find its first word.

(당신은 첫 단어를 찾아야 만하는 문자열을 받게됩니다.)

This is a simplified version of the First Word mission.

(이것은 First Word 임무의 단순화 된 버전입니다.)

  • Input string consists of only english letters and spaces.(입력 문자열은 영문자와 공백으로만 구성됩니다.)
  • There aren’t any spaces at the beginning and the end of the string.(문자열의 처음과 끝에는 공백이 없습니다.)

 

Input: A string.(문자열)

 

Output: A string.(문자열)

 

Example:

first_word("Hello world") == "Hello"

 

How it is used: The first word is a command in a command line.

                     (첫 번째 단어는 명령 행의 명령입니다.)

 

Precondition: Text can contain a-z, A-Z and spaces.

                   (텍스트에는 a-z, A-Z 및 공백이 포함될 수 있습니다.)

 

A>

def first_word(text: str) -> str:
    """
        returns the first word in a given text.
    """
    # your code here
    text = text.strip().split()

    return text[0]


if __name__ == '__main__':
    print("Example:")
    print(first_word("Hello world"))

    # These "asserts" are used for self-checking and not for an auto-testing
    assert first_word("Hello world") == "Hello"
    assert first_word("a word") == "a"
    assert first_word("hi") == "hi"
    print("Coding complete? Click 'Check' to earn cool rewards!")

 

O>

Example:
Hello
Coding complete? Click 'Check' to earn cool rewards!

Process finished with exit code 0

 

S>

https://py.checkio.org/

반응형

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

Python Learn the basics Quiz 57  (0) 2019.06.12
Python Learn the basics Quiz 56  (0) 2019.06.12
Python Learn the basics Quiz 55  (0) 2019.06.11
Python Learn the basics Quiz 54  (0) 2019.06.11
Python Learn the basics Quiz 53  (0) 2019.06.11
Python Learn the basics Quiz 52  (0) 2019.06.11