【发布时间】:2020-02-04 20:48:38
【问题描述】:
我的任务:编写一个名为findhypot 的函数。该函数将给出直角三角形的两条边的长度,它应该返回斜边的长度
我想出了以下解决方案:
def findhypot(a , b):
((a*a)+(b*b)%2)
return a , b
a = int(input("Pls lenter length of Opposite: "))
b = int(input("Pls enter the length of Adjascent: "))
print("The lenght of the hypotenous is",findhypot)
但我得到以下输出,而不是正确的值:
The lenght of the hypotenous is <function findhypot at 0xgibberish>
【问题讨论】:
-
您需要指定您要询问的内容。请注意,尽管
((a*a)+(b*b)%2)没有做任何事情,因为您不会将结果存储在任何地方,但我认为您不希望在那里取模 (%),并且您永远不会调用该函数。 -
另外,您正在打印对函数 findhypot 的引用,而不是调用它并打印返回值。它应该是
findhypot(a,b)。 -
@teukkam 该评论可能是答案的基础......
标签: python