发布网友 发布时间:2022-04-21 19:31
共1个回答
热心网友 时间:2023-07-13 21:08
if __name__ == "__main__":
m = float(input("请输入铁丝的长度:"))
n = float(input("请输入面积:"))
#高为h,宽为w=m/2-h
#n=h×(m/2-h)
#-h^2+(m/2)*h-n=0
#判断是否有解
if m*m/4.0-4*n < 0:
print("此问题无解!")
elif m*m/4.0-4*n == 0:
print("此问题一个解:")
h = (-m/2+(m*m/4.0-4*n)**0.5)/-2.0
w = m/2 - h
print("h=%f w=%f" % (h,w))
else:
print("此问题两个解:")
h = (-m/2+(m*m/4.0-4*n)**0.5)/-2.0
w = m/2 - h
print("h=%f w=%f" % (h,w))
h = (-m/2-(m*m/4.0-4*n)**0.5)/-2.0
w = m/2 - h
print("h=%f w=%f" % (h,w))
print()
代码及运行结果如图所示,望采纳!