STUDENT: Right, we're going to do that in a second, but the answer is Fibonacci numbers, we define the first two.
学生:听不见:,我们马上会试一试,但是答案是斐波那契数列,我们可以定义下最初的两个数。
Expect the address of an int but here in the context of the function itself inside the curly braces, it means go to that address.
一个整型数的地址,但是在函数,大括号中的环境中,意思是定位到那个地址。
If it is, in fact, positive, then we're going to go in here, but now notice what we're doing here.
如果这个数实际上是个正数,那么我们就到,这里面来,但是请注意我们在这做了什么。
In Numbers 14, for example, when the Israelites complain again, God is determined to destroy them, and Moses intervenes, and the intervention leads to a compromise.
比如,在《民数记》14中,当犹太人再次抱怨的时候,上帝决定毁灭他们,但是摩西阻止了,摩西的干涉,使上帝妥协了。
Now, this is supposed to be one sixth, but I know I don't want any transcendental numbers here.
现在,这是六分之一,但是,我知道我不想要任何的超越数。
But I can add to this some number, like 96, that'll still have the property that if you take two derivatives, you're going to get the same acceleration.
但是我可以在后面加上某个数,比如96,经过两次求导你仍会得到,同样的加速度
would have been the winning answer had everyone assumed that the average would have been constantly compounded down to 1, but since a couple of people chose the, I mean not incorrect answers, but the higher averages, then it was pushed up to 13.
如果大家都认为,平均数会一直下降到1的话,1应该是最终的答案,但是由于一部分人选择了,并不是说是错误的,但是却高于平均值的数,就把平均数推高到了13
But we might then wonder, for every person who gets less than the average amount of life-- suppose we take the median, take the amount of life that's exactly, 50 percent of the people get more, 50 percent of the people get less.
但是接着我们可能会想,对于所有活得比平均寿命要短的人-,假设我们取中间数,相对于平均寿命,刚好五成的人活得更长,五成的人活得更短。
It just throws the decimal point away and that's because, again, these are ints and the answer intuitively should be a floating point value, but I need to be more specific.
它直接把小数点后面的数值丢弃掉了,因为,凭直觉,那些整型数和结果应该是一个浮点数据,但是我需要一个更精确的数值。
But if it is not, it's going to print out a message here saying, you screwed up, somewhat politely, and it's going to go back around. So it'll just cycle until I get something of the right type.
但是输入不是浮点数的话,我这里就会显示一个消息说,你搞砸了,该稍微有点礼貌吧?,然后我们继续执行循环,一直到得到正确类型的输入。
If it's there, I'm done, if not, I keep walking down, and I only stop when I get to a place where the element I'm looking for is smaller than the value in the list., in which case I know the rest of this is too big and I can stop.
并且保持遍历,我只在当当前位置的数组元素,大于目标数时停止,这意味着剩下的元素都比目标元素大,但是其他的情况,我还是要遍历完整个数组。
The same number of electrons, but the number of protons keeps going up, up, up.
他们都是等电子,但是质子数在增加。
Could be ints, could be floats, could be a combination of things, some ints, some floats, some lists, some strings, some lists of lists, whatever.
但是我们知道数组内部的元素,可以是任何对象,可能是整数也可能是浮点数,也可能是对象的组合,一些整数。
The bits are still there, much like bits are still left when you erase a file on your hard disk but they're forgotten about.
二进制数还在那里,就像你在硬盘上删除一个文件,二进制还在那里,但是它们被遗忘了。
All right. What does this have to do with my divisor example? This says I can make tuples, but imagine now going back to my divisor example and I want to gather up the elements as I go along. I ought to be able to do that by in fact just adding the pieces in.
这意味着我可以创建元组了,但是想像下回到我们的除数的例子,在处理过程中我们想把目标数的除数,收集起来,我应该能够通过把这些数,一个一个加进来来实现这个目的,我正是要去这么做,也就是。
OK, once it gets to the end of that, what's it going to do? It's going to come down here and, oh. What's that doing? Well I cheated when I started. I said, somebody's giving me a perfect square, I'm looking for the square root of it. But suppose 15 I gave this thing 15, and asked it to run.
好,一旦到了循环的最后,程序会去做什么?程序会跳到这里来,噢,这是干什么的?好吧,当我开始的时候我有点小作弊的意思,我说过,我得到了一个完美的平方数,我要求这个数的平方根,但是假设下我得到的数是。
So yes, f is a float, but that solution is too late; we need to fix the problem sooner.
是的,f是一个浮点数,但是那个解决方案太迟了;,我们应该在次之前把问题解决。
But that little short hand there is doing exactly the same thing. It is adding that value into some digits and putting it back or signing it back into some digits. And I'll walk through that loop and when I'm done I can print out the total thing does. And if I do that, I get out what I would expect.
加上得到的这个数的,但是这个缩写声明其实是进行了同样的操作,它把我们得到的这个数加到一个数上面去,然后用和对这个数进行了重新赋值,在循环中会去遍历字符串,当完成循环后,程序会显示数字的总和,如果我运行,这个程序的话,我会得到我期待的结果。
They all have the same Z, the same proton number, but different A, which means number of neutrons varies.
有相同的Z,相同的质子数,但是不同的A,也就是中子数不同。
bug You're gonna run into innumerable bugs most likely, by bugs we mean mistakes, - behaviors that you didn't quite intend and yet they seem to be-- and yet your program seems to be misbehaving in some sense.
你可能会制造数不清的,对了,我们称bug为错误或,你完全没有预料到的行为,但是它们的确存在-,这样看来,你的作品在某种意义上可以说是行为不端。
I if I go over here, and I say float of three, it's going to do the conversion.
用float来处理3,它将能完成装换,但是如果我吧这个转化为浮点数。
It says, in either case in general, t of b-- and this is where I'm going to abuse notation a little bit but I can basically bound it by t, 12 steps plus t of b over 2.
我可以用一个,比12+t的数代表,这里有点不准确的地方,具体的步数依赖于奇数偶数,但是你们可以看到在两个case中。
Notice that once we've deleted the dominated strategies, you know I had said before about four people chose this strategy, and in here, about four people chose this strategy, but in this range 30 through 45, I had lots of people.
注意,一旦我们剔除了劣势策略,我们已知有四人选择了,在45到67之间的数,但是选择30到45的有不少
> But isn't f already a floating point?
>,但是f不是已经是一个浮点数了吗?
We knew this was trying to do squaring, so intellectually we know we can square -4, it ought to be 16, but what happens here?
我们知道程序是用来求平方数的,那么按理说我们可以来求-4的平方,也就是16,但是程序结果是怎么样的呢?
We're going to see variations of this, we're going to see a variation of it called recursion, a little later on, but for now we're just going to talk about how do we do iterations.
我们稍后会去,看它的变量,它的所谓的递归数的变量,但是现在我得先讲讲,怎么来实现迭代。
All right. I tried it on 2, I surely didn't expect a precise and exact answer to that but I got something, and if you square this, you'll find the answer kept pretty darn close to 2.
好,我试试求2的平方根,我当然不希望得到一个完全准确的答案了,但是我得到了一个近似值,试试将这个数平方一下,你会发现结果和2相当接近。
I can't rely on Professor Guttag if I give this- if this code to him, I can't rely on him to type in a float. Actually I can, because he's a smart guy, but in general, I can't rely on the user-- I wouldn't do it right to see if you did.
当Guttag使用这段代码的时候-,我不能相信他一定会输入一个浮点数,实际上我能因为他很聪明,但是总体上来讲,别相信用户一定会按照规则来-,我会故意做错来试试你的程序的。
So we'll talk a bit more about this idea of functions today, but, get int, again, can think of it as a black box, whose purpose in life is to prompt the human for input and pester the human if he or she doesn't actually give it int, but then once it has that, has entered it from the user, it's quote unquote, returns it to you.
所以我们进今天将多讨论点这个函数的概念,但是,GetInt,我们可以把它当做一个黑盒子,它的唯一目的是提示人们来输入,并且如果他或她没有,给它int数,则会纠缠用户,但是一旦它得到了,用户输入的int数,对输入进行引用,返回给你。
b OK. In this example I'd use b. All right, as b get-- b is the thing that's changing as I go along here, but it could be things like, how many elements are there in a list if the input is a list, could be how many digits are there in a string if the input's a string, it could be the size of the integer as we go along. All right.?
好,在这个例子里我会用,因为b是一直在变的东西,但是也可能是如下情况:,如果输入是数组的话,变化的就是数组的元素数,如果输入是字符串的话,变化的就是字符串的长度,如果是integer的话,可能就是这个数的大小,对不对?
应用推荐