Python의 수학 함수 | 세트 1(숫자 기능)

Python에서는 작업을 더 쉽게 만드는 다양한 함수를 정의하는 'math'라는 모듈을 가져옴으로써 여러 가지 수학 연산을 쉽게 수행할 수 있습니다. 1. 천장() :- 이 함수는 숫자보다 큰 최소 정수 값 . 숫자가 이미 정수인 경우 동일한 숫자가 반환됩니다. 2. 바닥() :- 이 함수는 숫자보다 작은 최대 정수 값 . 숫자가 이미 정수인 경우 동일한 숫자가 반환됩니다. 

Python
   # Python code to demonstrate the working of    # ceil() and floor()    # importing 'math' for mathematical operations    import   math   a   =   2.3   # returning the ceil of 2.3    print   (  'The ceil of 2.3 is : '     end  =  ''  )   print   (  math  .  ceil  (  a  ))   # returning the floor of 2.3    print   (  'The floor of 2.3 is : '     end  =  ''  )   print   (  math  .  floor  (  a  ))   

산출:

The ceil of 2.3 is : 3 The floor of 2.3 is : 2 

시간 복잡도: 오(1)

보조 공간: 오(1)


3. 팹() :- 이 함수는 절대값 번호의. 4. 계승() :- 이 함수는 계승 번호의. 숫자가 정수가 아닌 경우 오류 메시지가 표시됩니다. 

Python
   # Python code to demonstrate the working of    # fabs() and factorial()    # importing 'math' for mathematical operations    import   math   a   =   -  10   b  =   5   # returning the absolute value.    print   (  'The absolute value of -10 is : '     end  =  ''  )   print   (  math  .  fabs  (  a  ))   # returning the factorial of 5    print   (  'The factorial of 5 is : '     end  =  ''  )   print   (  math  .  factorial  (  b  ))   

산출:

The absolute value of -10 is : 10.0 The factorial of 5 is : 120 

시간 복잡도: 오(b)

보조 공간: 오(1)


5. 사본(a b) :- 이 함수는 다음과 같은 숫자를 반환합니다. 값은 'a'이지만 부호는 'b'입니다. . 반환된 값은 float 유형입니다. 6.gcd() :- 이 함수는 다음을 계산하는 데 사용됩니다. 두 숫자의 최대공약수 주장에서 언급했습니다. 이 함수는 Python 3.5 이상에서 작동합니다. 

Python
   # Python code to demonstrate the working of    # copysign() and gcd()    # importing 'math' for mathematical operations    import   math   a   =   -  10   b   =   5.5   c   =   15   d   =   5   # returning the copysigned value.    print   (  'The copysigned value of -10 and 5.5 is : '     end  =  ''  )   print   (  math  .  copysign  (  5.5     -  10  ))   # returning the gcd of 15 and 5    print   (  'The gcd of 5 and 15 is : '     end  =  ''  )   print   (  math  .  gcd  (  5    15  ))   

산출:

The copysigned value of -10 and 5.5 is : -5.5 The gcd of 5 and 15 is : 5 

시간 복잡도: O(분(cd))

보조 공간: 오(1)