floor python code example
Example 1: python floor
import math
x = 3.86356
math.floor(x)
#Returns: 3
math.ceil(x)
#Returns: 4
Example 2: floor python
def floor(k,b):
return b-k%b+k-b
print(floor(3,10)) # Prints: 0
print(floor(7.94,2.125)) # Prints: 6.375
Example 3: floor function in python
import math
print(math.floor(5.3))
output = 5
Example 4: floor python
math.floor(-23.11) : -24.0
math.floor(300.16) : 300.0
math.floor(300.72) : 300.0
Example 5: round python
# round(number, decimals).
# second parameter is optional, defaults to 0.
num1 = 1.56234
num2 = 1.434
print(round(num1)) # output: 2
print(round(num2)) # output: 1
print(round(num1, 3)) # output: 1.562
print(round(num2, 1) # output: 6.3
Example 6: python ceil
def ceil(k,b):
return b-k%b+k
print(ceil(5,10)) # Prints: 10
print(ceil(7.32,1.829)) # Prints: 9.145