所以我想计算长方体中两个最远点的距离。数学方程是 z^2 = a^2 + b^2 + c^2 但是当我这样做时它不会正确返回。
from math import *
dimension = input("What dimension: ")
if dimension == ("3D") or dimension == ("3d") or dimension == ("3"):
a = int(input("a = "))
b = int(input("b = "))
c = (sqrt((a**2) + (b**2)))
z = (sqrt((a**2) + (b**2) + (c)))
rounded_z = round(z, 4)
print(rounded_z,'cm')
else:
a = int(input("a = "))
b = int(input("b = "))
c = (sqrt((a**2) + (b**2)))
rounded_c = round(c, 2)
print(rounded_c,'cm')
例如:
如果 a = 6
和 b = 2
它应该是 7 cm Source。但它返回 6.8062!为什么?请帮忙。