【发布时间】:2019-09-17 05:49:13
【问题描述】:
基本上,我需要计算直角三角形的斜边
首先,我的代码定义三角形是否正确,然后根据两侧的长度计算该三角形的斜边,但它没有返回我需要返回的 h 值作为本练习的任务。
我不明白返回 h 有什么问题?
为什么代码没有返回它?
提前致谢
angle1 = input("what is a degree of the first angle? : ")
angle2 = input("what is a degree of the second angle? : ")
angle3 = input("what is a degree of the third angle? : ")
a1 = int(angle1)
a2 = int(angle2)
a3 = int(angle3)
length1 = input("what is a length of the first side? : ")
length2 = input("what is a length of the second side? : ")
l1 = int(length1)
l2 = int(length2)
def hypothenuse(a1, a2, a3, l1, l2):
if a1 != 90 or a2 != 90 or a3 != 90:
return ("\n sorry, but triangle sould be right -> one agle = 90 degrees")
else:
h = l1**2 + l2**2
return ("The hypothenuse of this triangle is equal to:", h)
hypothenuse(a1, a2, a3, l1, l2)
【问题讨论】:
-
是的。但是你没有用它做任何事情。也许你想做
print(hypoteneuse(a1....))? -
或者
description, h = hypotenuse(...),如果你以后想要这些值的话。但是如果没有直角会导致错误...
标签: python python-3.x return return-value