【发布时间】:2021-10-28 21:36:21
【问题描述】:
我正在编写一个程序来在 python 中输出一个数字的平方根。我当前的代码如下所示:
import math
num = int(input("Enter the number for which you want the square root"))
if math.floor(math.sqrt(num)) == math.ceil(math.sqrt(num)):
v = math.sqrt(num)
print(f"The given number is perfect square and the square root is {v} ")
elif num <0:
print("The square root of the given number is imaginary")
else:
print(f"The square root of the given number is \u221A{num}")
#\u221A is unicode for square root symbol
我当前的程序检查输入的数字是否是完全平方,然后显示平方根。如果它不是一个完美的正方形,它只会显示 √num。例如,如果 num 为 300,它将显示 √300。但我希望它显示为 10√3。关于我如何做到这一点的任何想法。我不希望我的结果中有任何小数。
【问题讨论】:
-
将数字拆分为其质因数并在其中找到相等的数字对!顺便说一句,这是一个软件开发社区,而不是数学社区。span>
标签: python square-root