바닥() 함수:
Python의 Floor() 메소드는 x의 바닥, 즉 x보다 크지 않은 가장 큰 정수를 반환합니다.
Syntax: import math math.floor(x) Parameter: x-numeric expression. Returns: largest integer not greater than x.>
다음은 Floor() 메소드의 Python 구현입니다.
파이썬
# Python program to demonstrate the use of floor() method> # This will import math module> import> math> # prints the ceil using floor() method> print> 'math.floor(-23.11) : '>, math.floor(>->23.11>)> print> 'math.floor(300.16) : '>, math.floor(>300.16>)> print> 'math.floor(300.72) : '>, math.floor(>300.72>)> |
문자열을 int로 변환
>
>
산출:
math.floor(-23.11) : -24.0 math.floor(300.16) : 300.0 math.floor(300.72) : 300.0>
ceil() 함수:
Python의 ceil(x) 메소드는 x의 상한값, 즉 x보다 크거나 같은 가장 작은 정수를 반환합니다.
Syntax: import math math.ceil(x) Parameter: x:This is a numeric expression. Returns: Smallest integer not less than x.>
다음은 ceil() 메소드의 Python 구현입니다.
파이썬
# Python program to demonstrate the use of ceil() method> # This will import math module> import> math> # prints the ceil using ceil() method> print> 'math.ceil(-23.11) : '>, math.ceil(>->23.11>)> print> 'math.ceil(300.16) : '>, math.ceil(>300.16>)> print> 'math.ceil(300.72) : '>, math.ceil(>300.72>)> |
인터넷을 사용하여
>
>
산출:
math.ceil(-23.11) : -23.0 math.ceil(300.16) : 301.0 math.ceil(300.72) : 301.0>
정수 나누기 및 덧셈 사용:
이 접근 방식에서는 x // 1을 사용하여 x의 정수 부분을 얻습니다. 이는 math.floor(x)와 동일합니다. x의 상한선을 얻으려면 x의 정수 부분에 1을 더합니다.
파이썬3
치유 도구 김프
x>=> 4.5> # Round x down to the nearest integer> rounded_down>=> x>/>/> 1> print>(rounded_down)># Output: 4> # Round x up to the nearest integer> rounded_up>=> x>/>/> 1> +> 1> print>(rounded_up)># Output: 5> |
>
>산출
4.0 5.0>
접근하다:
코드는 부동 소수점 x를 취하고 바닥 나누기를 사용하여 가장 가까운 정수로 내림합니다. 그런 다음 결과를 인쇄합니다. 그런 다음 바닥 나눗셈과 덧셈을 사용하여 x를 가장 가까운 정수로 반올림하고 결과를 인쇄합니다.
시간 복잡도:
round() 함수의 시간 복잡도는 일정합니다. 이는 대체 코드의 시간 복잡도도 일정하다는 것을 의미합니다. 원본 코드의 시간 복잡도도 일정합니다. 몇 가지 간단한 산술 연산만 사용하기 때문입니다.
공간 복잡도:
원본 코드와 대체 코드 모두 입력과 결과를 저장하는 데 몇 가지 변수만 사용하므로 공간 복잡도는 일정합니다.