Again, same kind of reasoning says, given some value x, I happened to pick a small one here, what's an easy way to do this? Well, let's just start at one. That's my variable I'm going to change and check.
好,尤其是,让我们到这里来,让我给大家看看第二个例子,让我把这个注释掉,这是我要解决的,第二个问题,假设我想找到一些整数的,所有除数,我想要找出来这个数的所有的除数。
So strings also support things like selection, slicing, and a set of other parameters, other properties. And let's just look at that.
如果我要到这里来的话,就得把这儿注释掉,这里是我已经建立的。
And so, in fact, the version that I commented out which is also in your handout and I'm now going to uncomment, let's get that one out, get rid of this one-- notice the only change.
所以事实上,我之前注释掉的版本,你们的讲义上也有,我打算把注释去掉,我们把他拿出来,把这个丢到一旁,注意下唯一的改变。
But notice what this does. The first thing it does is, it says, let's check and make sure x is greater than or equal to 0. If it isn't, notice what's going to happen. None of that block is going to get executed, and it's going to come down here and print out a useful piece of information, which says, hey, you gave me a negative number. I don't know how to do this.
做的是和以前一样的事情,但是注释它做了什么,第一件做的事情就是,程序说,要去检查并且确信x是大于等于0的,如果不是的话,请注意会发生什么,下面的代码都不会被执行,程序会到这里来然后显示一些有用的信息,信息会说,嘿,你给了我一个负数,我不知道该怎么弄这个了。
应用推荐