What should I add to my code to make return value 15.58
, without using any library ?
def solution(side):
result = (side**2)*(3**(0.5))/4
return result
# return = 15.5885
What should I add to my code to make return value 15.58
, without using any library ?
def solution(side):
result = (side**2)*(3**(0.5))/4
return result
# return = 15.5885
def solution(side):
result = (side**2)*(3**(0.5))/4
return round(result,2)
# return = 15.59
Original result value: 15.5884572681
Use floor
to round down to get 15.58
:
import math
def solution(side):
result = (side**2)*(3**(0.5))/4
return math.floor(result*100)/100
print(solution(6)) # prints 15.58
Use round
with precision 2
to get 15.59
:
def solution(side):
result = (side**2)*(3**(0.5))/4
return round(result,2)
print(solution(6)) # prints 15.59
Use round to ceil value :
# First we take a float and convert it to a decimal
result = (side**2)*(3**(0.5))/4
# Then we round it to 2 places
output = round(result,2)
print output
You can use math.floor to get 15.58 :
import math
result = (math.floor(result * 100)) / 100.0// 15.58