By putting it in a function bug if I find a bug and I change my program I can just run the function again.
把我输入的值放到一个函数里,如果以后我在程序中发现了一个,并对程序进行更改的话,我可以直接。
OK. I get the two values in, what do I need to do, well, you sort of know that, right?
好,有了这两个输入值了,我接下来将要做的,你知道对不对?
s1 We're assigning to s1 the string that the user typed in.
我们把用户输入的字符串赋值给。
OK, says it says enter a float. I give it something that can be converted into a float, it says fine. I'm going to go back and run it again though. If I run it again, it says enter a float.
好了,看到他说输入一个浮点数,我输入它可以转换为浮点数的值,那没问题,我回过来再运行一遍,如果我再运行一遍。
You notice what it did, it printed out that little, right up here I'd said enter a number and that's what it's printed out, so I can enter a number and it prints it out.
注意这个程序做了些什么,显示出了指定值,然后显示需要输入个数字,然后程序会显示这个数字,我输入一个数字然后程序显示了它。
Need to get the base in. Second thing I want to do, I need to get the height, so I'm going to input a value for the height, also as a float, a floating point.
也就是输入底的值,第二件我想要做的,事情就是得到三角形的高,因此我会输入一个值作为三角形的高,同样也是一个浮点数。
It's going to do a lot of type checking for you before it actually passes things back.
它会在将输入值进行计算之前,做很多类型检查。
Now what I'm going to try and do is read in a set of values, but I'm going to give a type of value as well as the messages.
现在我要做的是输入一些值,并关注异常,我会输入消息以及一种其他的值。
Why is that better than typing them?
这比起直接输入这些值来由什么好处呢?
But here's a new and improved, I think, version of increment; ++ returns nothing, takes nothing, but it does perform plus plus, but I did something stupid.
但这里是一个新的,改进了的increment版本;,没返回值,没输入值,但它执行的是,但是我做了件愚蠢的事情。
But if I say turn this into a float, ah it throws a value error exception.
它就会抛出一个值错误异常了,它会告诉我输入了一种错误的值。
So it does that for us so that you can get away with just knowing the address of the first byte and it will make sure that you know when to stop by including the special value so, in fact, get the string if you type in a three-letter word, we allocate four bytes no matter what because we need an additional byte 0 for this special sentinel value back slash zero at the very end.
它为我们做了这些事情,这样我们就可以,通过第一个字节的地址,它还可以通过包含一个特殊的值,来保证在哪里停止,如果你输入了一个三个字母的单词,就可以获得那个字符串,不管怎样,我们分配四个字节,因为我们在末端需要一个额外的字节,来保存这个特殊的标志值--反斜杠。
Well this is leading up to why I want to gather things together in classes to start with.
收集起来的话题了,在Python中这么输入,然后得到值是完全合法的。
It's going to print out even or odd, depending on whether the value I put in, which is x in this case, is even or odd.
它会打印奇数或者偶数,这取决于我输入的值,也就是这个例子中的x,是奇数还是偶数。
It ran through that sequence of instructions, in particular it bound x to the value three, x and then it took x times x, got the value of x multipied by x, which of course is nine, bound that to the value of x, and then it printed out the value, and now it's sitting here waiting for an input.
程序按照指令的顺序去执行的,首先是把x和3这个值进行了绑定,然后把x乘以,得到了x乘以x的值,当然也就是9了,然后把x和这个值进行了绑定,然后显示出这个值,然后就等待输入。
I'm passing as input the value in X, which is two.
我把那个值当输入传给X,那个值是。
If I get 0 I return 1.
如果我输入的值是0我会返回。
Because in doing that, Python would then have a value that it could pass on into some other part of a computation, and if it wasn't what I wanted, I might be a long ways downstream in the computation before I actually hit some result that makes no sense.
因为如果这样做的话,Python会将,输入的值传递到下面的,一些运算中去,如果这个值的类型不是我想要的,我可能会在得到,一个毫无意义的结果之前,经历一个很长时间的,计算过程。
I would like you to look at this piece of code right here called isPalindrome.
我将会输入一个字符串,命名为s,并局部赋值。
What value of inputs, what values of x will this run correctly for?
这个程序正常运行的话对于输入的值,也就是x的值,有什么要求呢?
And conceptually, the idea of cubing a value feels like you could package that up into a little box, a little tool that takes input, a value, and returns output the answer A* so you don't have to constantly do A star, A*A So this program ,at the end of today, is pretty much the same thing.
概念上,算一个值的立方就像是,你可以把一个值打包放在一个小盒子里,一个用来接收输入的工具,一个值,然后返回一个答案,所以你并不需要一直使用,等等。,A,star,,A,,and,so,forth。,这个程序,最后,是一个差不多的东西。
应用推荐