定义一个函数,然后插入数字 [英] Define a function and then plug the numbers
本文介绍了定义一个函数,然后插入数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试定义一个函数来计算三角形的面积,然后输入高度和基数来计算输出。但是,它不会产生任何结果,我想知道我是否正确?
I'm trying to define a function to calculate the area of a triangle, followed by inputing the height and base to calculate the output. However, it doesn't produce any result, I wonder if I'm correct?
def tri_area(base, height):
return base * height / 2
tri_area(2, 3)
推荐答案
打开ipython控制台和类型:
Open ipython console and type:
In [1]: def tri_area(base, height):
...: return base * height / 2
关闭 Shift
+ 返回
并输入下一行
close the line with Shift
+ Return
and type the next line
In [2]: tri_area(2, 3)
并用关闭它返回
。您将看到您的输出:
and close it with Return
. You will see your output:
Out[2]: 3
这篇关于定义一个函数,然后插入数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文