Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Nearest Square Number by brownie57
def nearest_square(number):
import math
s = math.sqrt(number)
f = math.floor(s)
c = math.ceil(s)
return f**2 if s-f < c-s else c**2
if __name__ == '__main__':
print("Example:")
print(nearest_square(8))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert nearest_square(8) == 9
assert nearest_square(13) == 16
assert nearest_square(24) == 25
assert nearest_square(9876) == 9801
print("Coding complete? Click 'Check' to earn cool rewards!")
Aug. 12, 2018