ADM-201 dump PMP dumps pdf SSCP exam materials CBAP exam sample questions

【用代数讲计算机科学】什么是函数 – 译学馆
未登录,请登录后再发表信息
最新评论 (0)
播放视频

【用代数讲计算机科学】什么是函数

CS in Algebra: Functions

想一下 你想让某个人做一个三明治 但是他们又不知道’做一个三明治’
Imagine if every time you wanted someone to make a sandwich, but they had no understanding
是什么意思 你必须需把制作三明治的步骤给描述出来
of what make a sandwich means, you’d have to describe every last step of sandwich-making.
从打开冰箱到切面包 再从放置调料到
From opening the fridge to slicing the bread, to layering the ingredients to spreading the
抹匀
condiments.
如果你曾经不止一次需要制作三明治 你可能会想要一个
If you ever needed someone to make a sandwich more than once, you’d want to agree on a common
普通的快捷方式来制作三明治
shorthand for make a sandwich.
你可能会想能够简单制作瑞士火腿 黄油果冻坚果
And you’d probably want make a sandwich to be generic enough to allow someone to make
豆芽金枪鱼三明治
a ham and swiss or peanut butter and jelly or tuna and sprouts.
把制作三明治变成一个能接收特定参数 例如 馅 调料
Make a sandwich becomes a new function that can take in certain inputs such as filling,
和面包的功能 然后执行一组操作
condiments and bread and performs a set of operations on them.
把调料抹在面包上 把馅放在两片面包中间
Spreading the condiments on bread, layering the filling between the two slices and returns
并且返回值类型为 三明治的函数
an object of type: sandwich.
还记得我们上期的五十个红色三角形吗
Remember our fifty red triangles from the last stage?
如果我们不想要五十个一模一样的红色多边形呢
What if we didn’t want fifty of the exact same shape but fifty red polygons, each one
而是每个都比上一个多一条边
with one more side than the last.
第一个是三角形 接着是四方形 五角形 六角形 等等
First triangle, then square, a pentagon, a hexagon and so on.
我们能仅定义一个每次不返回同样形状的新函数
We can do just that by defining a new function that doesn’t return the same shape every time.
让我们把新函数叫做 My Polygon
Let’s call our new function My Polygon.
它能接收一个简单的数字表示边并且返回相应的多边形
It should take a single number for sides and return a red polygon of given sides.
我们可以用从三到五十的每一个数字调用这个函数
We can call this function with every number from three to fifty-three to fill up our screen
来用红色多边形填充我们的屏幕
with red polygons.
在课程的一开始我们已经讨论过数学作为一种语言
At the beginning of this course we talked about math as a kind of language.
当我们定义变量的时候 本质上我们是在向语言中添加一个新东西或者名词
When we define variables, we are essentially adding new things or nouns to our language.
当我们定义函数的时候 我们是在用新的动作或者动词来扩展我们的语言
When we define functions, we expand our language with new actions or verbs.
下一期 你将会编写一个简单的函数用来
In this next stage, you’re going to edit and write simple functions to output a variety
输出多种图像
of images.
为了进入函数内部 你可以点击在函数快角落的 edit 单词
To get inside a function, you click the word edit in the corner of the function’s block.
从那儿 你可以完成你新函数的协议 包括 名称
From there, you can complete the contract for your new function, including a name, domain
域和范围
and range.
这里也有一块用来描述你的函数应该做什么的部分
There’s also a section for you to write a description of what your function should do.
函数协议下面是定义函数的区域
Underneath the function contract is an area for you to build your function definition.
确保使用这些当你填充域时出现的参数块
Make sure to use the parameter blocks that were generated when you filled out the domain.
当你调用你的函数时 你传过来的值会作为输入替换掉这些占位符
When you call your function, the values that you passed as inputs end up in these placeholders.

发表评论

译制信息
视频概述
听录译者

收集自网络

翻译译者

【B】Cod

审核员

【MR】拾月

视频来源

https://www.youtube.com/watch?v=wBh7dOcw02M

相关推荐