数字が完璧な立方体かどうかをチェックするコードを作る必要がありますが、何らかの理由で27を超える立方体があるとすれば、その根はx.99999999です。 (つまり、3.9999 & 125 **(1/3)を4.9999として64 **(1/3)を返します。完璧な立方体を確認する
n = int(input("What number would you like to check if it is a cube?"))
def is_cube(n):
guess = n**(1.0/3.0)
if (guess)%1 == 0:
print(True, "it's cubed root is", guess)
else:
print(False, "it's cubed root is", guess)
is_cube(n)
浮動小数点数は正確ではありません。https://docs.python.org/3/tutorial/floatingpoint.html 10進数モジュールを使用してください。https://docs.python.org/3/library/decimal.html#モジュール小数点 –