Created
December 2, 2020 06:20
-
-
Save angeloped/e6d147de7eecd8138ba60d5af05ddf4e to your computer and use it in GitHub Desktop.
Determine the nearest perfect cube within the range from 0 to n.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def near_cube(num): | |
for i in range(num,0,-1): | |
if (i**(1.0/3))%1==0: # if perfect cube | |
break | |
return i | |
print(near_cube(730)) | |
print(near_cube(729)) | |
print(near_cube(29)) | |
print(near_cube(27)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment