라벨이 math인 게시물 표시

파이썬[Python]: math - gcd 함수

math 모듈 - gcd 함수(function) /// 설명 인자로 들어온 수들의 최대 공약수를 구합니다. 인자가 없거나, 모두 0 이면 0을 반환합니다. ※ 형식 math.gcd(*integers) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 import  math   print (math.gcd())   # 0 print (math.gcd( 0 ,  0 ,  0 ,  0 ))   # 0 print (math.gcd( 3 ,  0 ,  0 ,  0 ))   # 3 print (math.gcd( 3 ,  1 ,  0 ,  0 ))   # 1 print (math.gcd( 1 ,  2 ,  3 ,  4 ,  5 ))   # 1 print (math.gcd( 100 ,  200 ))   # 100     # the greatest common divisor   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: math - fsum 함수

math 모듈 - fsum 함수(function) /// 설명 반복 가능한 객체(iterable)에 있는 요소들의 (정확한) 합을 구합니다.(소수형식으로 반환) ※ 형식 math.fsum(iterable) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 import  math   test_list  =  [ 1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 ,  10 ]   print (math.fsum(test_list))   # 5.5 print (sum(test_list))   # 5.5   test_list  =  [. 1 , . 2 , . 3 , . 4 , . 5 , . 6 , . 7 , . 8 , . 9 ,  1. 0 ]   print (math.fsum(test_list))   # 5.5 print (sum(test_list))   # 5.5   test_list  =  [. 1 , . 1 , . 1 , . 1 , . 1 , . 1 , . 1 , . 1 , . 1 , . 1 ]   print (math.fsum(test_list))   # 1.0 print (sum(test_list))   # 0.9999999999999999   test_list  =  [. 2 , . 2 , . 2 , . 2 , . 2 , . 2 , . 2 , . 2 , . 2 , . 2 ]   print (math.fsum(test_list))   # 2.0 print (sum(test_list))   # 1.9999999999999998     # [a, b, c, d, e, ... , f] # return = a + b + c + d + e + ... + f   Colored by Color Scripter cs

파이썬[Python]: math - frexp 함수

math 모듈 - frexp 함수(function) /// 설명 분수와 지수의 튜플을 반환합니다.(0.5 <= 절대값(분수) < 1, 2^지수). 인자 x 가 0 이면 (0.0, 0) 을 반환합니다. ※ 형식 math.frexp(x) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import  math   print (math.frexp( 0 ))   # (0.0, 0) print (math.frexp( 0. 1 ))   # (0.8, -3) print (math.frexp( 1. 1 ))   # (0.55, 1) print (math.frexp( 2. 1 ))   # (0.525, 2) print (math.frexp( 3. 1 ))   # (0.775, 2) print (math.frexp( 4. 1 ))   # (0.5125, 3) print (math.frexp( 21. 8125 ))   # (0.681640625, 5)   # x = 0, tuple(0.0, 0) # form : float = fraction * 2^x, 0.5 <= abs(fraction) < 1 # # tuple = (fraction, x)   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: math - fmod 함수

math 모듈 - fmod 함수(function) /// 설명 C언어 라이브러리에 정의되어 있는 값을 반환합니다.(r = x - ny, n = x / y, sign = x's sign) 이 값은 파이썬의 x % y 와 다를 수 있습니다. ※ 형식 math.fmod(x, y) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 import  math   # x > 0, y > 0 --------------- same result # x > y print (math.fmod( 15 ,  2 ))   # 1.0 print ( 15  %  2 )   # 1   # x == y print (math.fmod( 15 ,  15 ))   # 0.0 print ( 15  %  15 )   # 0   # x < y (remainder = x) print (math.fmod( 15 ,  20 ))   # 15.0 print ( 15  %  20 )   # 15   # x < 0 or y < 0 ------------- I'm not sure print (math.fmod( 2 ,  - 102 ))   # 2.0 print ( 2  %  - 102 )   # -100   print (math.fmod( - 2 ,  - 2 ))   # -0.0 print ( - 2  %  - 2 )   # 0   print (math.fmod( - 2 ,  102 ))   # -2.0 print ( - 2  %  102 )   # 100   print (math.fmod( - 350 ,  - 100 ))   # -50.0 print ( - 350  %  - 100 )   # -50   # ...   Co

파이썬[Python]: math - floor 함수

math 모듈 - floor 함수(function) /// 설명 x(정수) 와 같거나 x(실수) 보다 작은 정수들 중 가장 큰 정수를 반환합니다.(소수점 내림) ※ 형식 math.floor(x) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import  math   print (math.floor( 1 ))   # 1 print (math.floor( 1. 1 ))   # 1 print (math.floor( 1. 2 ))   # 1 print (math.floor( 1. 3 ))   # 1 print (math.floor( 1. 4 ))   # 1 print (math.floor( 1. 5 ))   # 1 print (math.floor( 1. 6 ))   # 1 print (math.floor( 1. 7 ))   # 1 print (math.floor( 1. 8 ))   # 1 print (math.floor( 1. 9 ))   # 1 print (math.floor( 2 ))   # 2   # ---|<--------|<--------|<--------|<-- # ...1.........2.........3.........4...   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: math - factorial 함수

math 모듈 - factorial 함수(function) /// 설명 0 또는 양의 정수 x 의 계승을 반환합니다. ※ 형식 math.factorial(x) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 import  math   print (math.factorial( 0 ))   # 1 print (math.factorial( 1 ))   # 1 print (math.factorial( 2 ))   # 2 print (math.factorial( 3 ))   # 6 print (math.factorial( 4 ))   # 24 print (math.factorial( 5 ))   # 120   # factorial: https://ko.wikipedia.org/wiki/%EA%B3%84%EC%8A%B9 # # x! = x * (x - 1) * (x - 2) * ... * 3 * 2 * 1   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: math - fabs 함수

math 모듈 - fabs 함수(function) /// 설명 x 의 절대값을 반환합니다. ※ 형식 math.fabs(x) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import  math   print (math.fabs( 1 ))   # 1.0 print (math.fabs( - 1 ))   # 1.0 print (math.fabs( 0. 1 ))   # 0.1 print (math.fabs( - 0. 1 ))   # 0.1     # |x| = sqrt((x^2)), sqrt = squart root # # |x| = x, (x > 0) # |x| = 0, (x = 0) # |x| = -x, (x < 0)   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: math - copysign 함수

math 모듈 - copysign 함수(function) /// 설명 x 값에 절대값을 취한 후, y 의 부호를 적용하여 반환합니다. ※ 형식 math.copysign(x, y) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 import  math   print (math.copysign( 0. 1 ,  0. 0 ))   # 0.1 print (math.copysign( - 0. 1 ,  0. 0 ))   # 0.1 print (math.copysign( 0. 1 ,  - 0. 0 ))   # -0.1 print (math.copysign( 0. 1 ,  - 0. 0 ))   # -0.1     # the magnitude of x = absolute value of x   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: math - comb 함수

math 모듈 - comb 함수(function) /// 설명 서로 다른 n 개 중에서 순서를 생각하지 않고 k 개를 선택하는 방법을 나타냅니다.(조합) ※ 형식 math.comb(n, k) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 import  math   print (math.comb( 3 ,  2 ))   # 3   print () print ( 'permutation = p' ) print ( '= n * (n-1) * (n-2) * ... * (n-k+1), ( 0 < k <= n )' ) print ( '= n! / (n - k)!, ( 0 <= k <= n )\n' ) print ( 'combination = c' ) print ( '= p / k!, ( 0 <= k <= n )' ) print ( '= n! / (k! * (n - k)!), ( 0 <= k <= n )' )   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: math - ceil 함수

math 모듈 - ceil 함수(function) /// 설명 x(정수) 와 같거나 x(실수) 보다 큰 정수들 중 가장 작은 정수를 반환합니다.(소수점 올림) ※ 형식 math.ceil(x) reference https://docs.python.org/3/library/math.html#module-math /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import  math   print (math.ceil( 1 ))   # 1 print (math.ceil( 1. 1 ))   # 2 print (math.ceil( 1. 2 ))   # 2 print (math.ceil( 1. 3 ))   # 2 print (math.ceil( 1. 4 ))   # 2 print (math.ceil( 1. 5 ))   # 2 print (math.ceil( 1. 6 ))   # 2 print (math.ceil( 1. 7 ))   # 2 print (math.ceil( 1. 8 ))   # 2 print (math.ceil( 1. 9 ))   # 2 print (math.ceil( 2 ))   # 2   print ( '-->|-------->|-------->|-------->|---' ) print ( '...1.........2.........3.........4...' )   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –