본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 47

반응형

Q>

Let's work with numbers.

(숫자로 작업 해 봅시다.)

You are given an array of numbers (floats).

숫자 배열 (실수)이 주어집니다.

You should find the difference between the maximum and minimum element.

(최대 요소와 최소 요소의 차이점을 찾아야합니다.)

Your function should be able to handle an undefined amount of arguments.

(함수는 정의되지 않은 양의 인수를 처리 할 수 ​​있어야합니다.)

For an empty argument list, the function should return 0.

(빈 인수 목록의 경우 함수는 0을 반환해야합니다.)

Floating-point numbers are represented in computer hardware as base 2 (binary) fractions.

(부동 소수점 숫자는 컴퓨터 하드웨어에서 기본 2 (2 진수)로 표시됩니다.)

So we should check the result with ±0.001 precision.

(따라서 우리는 ± 0.001의 정밀도로 결과를 확인해야합니다.)
Think about how to work with an arbitrary number of arguments.

(임의의 수의 인수로 작업하는 방법에 대해 생각하십시오.)

 

Input: An arbitrary number of arguments as numbers (int, float).

        (임의의 수의 인수를 숫자 (int, float)로 사용합니다.)

 

Output: The difference between maximum and minimum as a number (int, float).

           (최대 값과 최소값의 차이 (int, float).)

 

Example:

checkio(1, 2, 3) == 2
checkio(5, -5) == 10
checkio(10.2, -2.2, 0, 1.1, 0.5) == 12.4
checkio() == 0

 

A>

# *args 입력값이 몇개여도 받을수 있다.
def checkio(*args):
    # 하나라도 겂이 입력 되면 가장 큰 값과 가장 작은 값을 빼고 리턴
    if args:
        return max(args) - min(args)
    # 하나라도 없으면 0
    else:
        return 0


# These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
    def almost_equal(checked, correct, significant_digits):
        precision = 0.1 ** significant_digits
        return correct - precision < checked < correct + precision


    print('Example:')
    print(checkio(1, 2, 3))

    assert almost_equal(checkio(1, 2, 3), 2, 3), "3-1=2"
    assert almost_equal(checkio(5, -5), 10, 3), "5-(-5)=10"
    assert almost_equal(checkio(10.2, -2.2, 0, 1.1, 0.5), 12.4, 3), "10.2-(-2.2)=12.4"
    assert almost_equal(checkio(), 0, 3), "Empty"
    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

 

O>

Example:
2
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 49  (0) 2019.06.10
Python Learn the basics Quiz 48  (0) 2019.06.10
Python Learn the basics Quiz 46  (0) 2019.06.10
Python Learn the basics Quiz 45  (0) 2019.06.10
Python Learn the basics Quiz 44  (0) 2019.06.10