I will be posting code that you can play with, and I suggest you go through exactly this kind of exercise.
我给你一些你用的上的代码,我建议你们,多进行一些这种实验。
So we left off last time with looking at a bit of coding and teasing you with the upcoming problem set.
我们上次讲到了查看一些代码,并且给你们带来这下面的习题。
All right, those pieces of code inherently involved something that does depend on the size of the input, or on the particular input.
好,这些代码,肯定会涉及到一些,与输入的大小相关的东西,或者说与特定输入相关。
What we will distribute for most lectures is a handout that's mostly code examples that we're going to do.
我们在大多课堂上会散发一些,印着我们要做的,代码范例的资料。
You will be able to infer from some of our code how in fact you can implement some more sophisticated programs.
你可以从一些代码中推断出,应该要怎样实现一些较复杂的程序。
Because I might have written some code in which I'm expecting that integer particular variable to have an integer value.
因为我可能写了一些代码,来把一些,变量的类型,指定为。
I've read through the same thing twenty times and I've missed something obvious. Someone who's never seen it before looks at and says, did you really mean to do this?
但是它们有一双旁观者之眼,我把同一段代码读上20遍,都会漏掉一些很明显的错误,从没看过这段代码的人会告诉我?
And I want to suggest that what we've done is, we've outlined a lot of the basic elements of programming. A lot of the basic elements we're going to need to write code.
我想提醒大家我们学习的是,我们学习了很多关于,编程的基础的东西,一些我们编写代码需要的基础的东西。
I know this is a simple example, but when you mature as a programmer, one of the first things you should do when you sit down to tackle some problem is write something like this pseudo code.
我知道这是个很简单的例子,但是当你们成长为一名程序员后,当你们碰到问题后第一件事情就是,该写一些类似于,伪代码的东西。
Now we're gonna hand you some framework, that code that we wrote with some blanks to get you accustomed to the idea of one, writing larger programs than time might allow if you were doing it on your own.
现在就提供给你们一些框架,在代码中有些空白,是为了让你们了解其中的思想,如果是你自己,若时间允许,那就尽量写大的程序。
If somewhere later on in the code it shifts to string, I might not be manipulating that and getting actual values out, but not what I wanted, and it's going to be really hard for me to chase it back.
然后后面的一些代码,把变量类型变为了字符串,我可能不会通过实际操作,去取得实际的变量的类型,但是这并不是我想要的类型,而且对我来说把类型,变回去也很困难。
And for reference, incidentally, in case you ever forget what the point of some exercise was, I'll almost always comment the code up top with a quick sentence or two that reminds you what this program does.
顺便作为参考,为了避免我们可能忘记一些代码的意思,我通常会用一两个简单的句子,在上面作出注释,那样会提醒我们这个程序是干嘛的。
So when you're writing a program in this language and many others, if you wanna make a comment to yourself or for other people who are reading this with their TF or fellow colleagues, you use what are called comments.
当你用这样那样的语言写程序时,为了便于自己或他人,阅读我们写的代码,我们必须得做一些注解,这就是所谓的注释。
OK, let me comment this out, and let's look at this next little piece of code. All right.
好,让我添加一点注释,然后让我们看看,下面的一些代码,好。
> That lets the compiler know that you want to use some actual compiled code from that library.
>,那是告诉编译器我们想要在程序库中,使用一些当前的编译后的代码。
But I got a couple of other of these strange looking things in there with underbars to them.
我可以在这片代码中看到这些,然后我需要一些可以给我,返回这些信息的东西,但是这里还有一些看起来。
Sudoku And then Sudoku we did last year where it actually becomes a little more interesting where we start providing students not with a blank slate, but with some distribution code.
我们去年做的,实际上更有意思,我们给学生的不是一块白板,而是一些分布式代码。
And for a couple of reasons, one this is the first P set where we're actually gonna give you code to work from.
由于一些原因,这里是第一个习题集,在此我们提供了一些代码供大家参考。
Second thing to notice, is that little piece of pseudo code is telling me things about values.
然后需要注意的是,这些伪代码告诉了一些关于值方面的事情,我需要一个浮点数。
It's words to you, or to the reader of the code, that are telling you what's going on inside of this code. OK?
注释是一些对你,或者对代码阅读者说的一些话,告诉你这段代码,是干什么的,对不对?
That means it was something I didn't understand. So I'm going to be cautious and systematic.
这就意味着代码中有一些,我没有理解的东西,因此我需要谨慎,并且系统化的去寻找这个错误。
If you want to make sure both conditions are true and they both have to be true for any code to be executed, use ampersand ampersand.
如果你想保证两个条件都成立,或者它们两个都必须为真值,才能执行一些代码,那就使用“&&“
And to do this, I'm going to use some code that I've already typed in.
为了达到这个目的,我会去使用一些,我已经写好的代码。
I will tell you that a good programmer, at least in my mind, may actually go back and modify the pseudo code as they realize they're missing things, but it's easier to do that when you're looking at a simple set of steps, than when you're in the middle of a pile of code.
至少我认为是这样的,如果他们发现遗漏了,一些步骤的话会,回过头去修改伪代码,但这当你面对一些大致的步骤时,这个过程就会比,面对一堆代码要简单的多。
First one, when I write a piece of code, especially code that has branches in it, when I design test cases for that piece of code, I should try and have a specific test case for each possible path through the code.
第一点,当我们写代码的时候,尤其是一些含有分支语句的代码的时候,当我为这些代码,设计测试用例的时候,我应该为每一个可能的程序路径,都设计一个特别的用例。
So we've embedded some error checking, if you will, into our implementations.
所以我们植入了一些错误校验,如果你愿意,在我们的执行代码里。
And what we'll be doing is, early next week we'll be distributing code, which we'll ask you to study, about two or three pages of code, and then on the final we'll be asking you questions about the code.
我们现在要做的就是,在下周前半部分我们会发一些代码,给你们去研究,大概有两三页纸,然后在期末的时候,我们会问你一些有关代码的问题。
I should also warn you that this code includes some Python concepts, at least one, that you have not yet seen.
我得事先说明这个代码中,包括了一些你没见过的Python语言的概念,至少一个。
Because what you don't see in this file is any code a that actually says put a letter of the alphabet at the top left hand corner of the screen and then put the next character to the right in other words, I'm taking for granted at this moment in time that my computer knows how to print something to the screen.
就是这些你在本文件中看不到的一些代码,实现了将首字母,放在屏幕的左上角,然后把其他字母加在其右边,我想当然地认为,我的电脑知道如何打印相应信息到屏幕上。
Most folks at least have something along those lines.
至少大部分人有一些东西沿着那些代码行。
应用推荐