본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 56

반응형

Q>

Your mission here is to create a function that gets a tuple and returns a tuple with 3 elements - the first, third and second to the last for the given array.

(여기서 당신의 임무는 튜플을 얻고 주어진 배열의 첫 번째, 세 번째, 두 번째의 세 요소를 가진 튜플을 반환하는 함수를 만드는 것입니다.)

 

Input: A tuple, at least 3 elements long.

        (최소한 3 요소 길이의 튜플.)

 

Output: A tuple.

           (튜플.)

 

Example:

easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)) == (1, 3, 7)
easy_unpack((1, 1, 1, 1)) == (1, 1, 1)
easy_unpack((6, 3, 7)) == (6, 7, 3)

 

A>

def easy_unpack(elements: tuple) -> tuple:
    """
        returns a tuple with 3 elements - first, third and second to the last
    """
    # your code here
    return elements[0], elements[2], elements[-2]

if __name__ == '__main__':
    print('Examples:')
    print(easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)))

    # These "asserts" using only for self-checking and not necessary for auto-testing
    assert easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)) == (1, 3, 7)
    assert easy_unpack((1, 1, 1, 1)) == (1, 1, 1)
    assert easy_unpack((6, 3, 7)) == (6, 7, 3)
    print('Done! Go Check!')

 

O>

Examples:
(1, 3, 7)
Done! Go Check!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

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

Python Learn the basics Quiz 58  (0) 2019.06.12
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