Recording Dave's words in Lesson 8

---Biggest Solution:

We should try to find a way to make the code smaller and simpler,easier to understand. and if it is easier to understand, that means it is also easier to write it correctly.

so the easier way to write this is to use the "bigger" procedure that we define earlier in this unit. And if we remember what that was, we defined "bigger" like this:
......

so if we have "bigger" defined, what we already did, then we can define "biggest" in a simpler way. we don't need all these "if"s. All we need to do is to use "bigger" twice.

well then we can think about "biggest" this way. So we've got 3 inputs coming into "biggest", and it should produce 1 output--the biggest of these 3. Well, we've got the "bigger" procedure, so we could use "bigger" to compare two, ......,so this is composing 2 calls to "bigger". We want the inputs to the first call to be "a" and "b". We want the output of that call to be one of the inputs to the next call. So here is how we can do that, in code. We can return the result directly.
'''
def biggest(a,b,c):
return bigger(bigger(a,b),c)
'''

So that is a much shorted way to find "biggest". It takes advantage of the fact that we already defined a procedure that does this for 2 inputs. And now we want to do the "biggest" for 3 inputs. There is actually an even easier way to do it, and that's using a built-in operator. There's a built-in operator ,"max", and we could use "max" directly to implement "bigger", just returning the "max" of a, b and c. If we actually knew about the built-in operator, "max", well then, we wouldn't need to find "biggest" at all.

But the important thing to see here is that we can define procedures ourselves. And, in fact, we've seen enough at this point that every built-in procedure in Python, you could actually define yourself. And it is even better than that, that you actually know enough at this point, that you could write every possible computer program, using just things we have seen. And this is a pretty astounding result, and i mean this in a very strong sense, that everything that could be computed mechanically by any machine can be described using a program that only used the things that we've seen so far.

** All you need is procedures, simple arithmetic with the comparisons, and "if" statements.**

And this is a pretty amazing thing. This was shown by Alan Turing, back in the 1930s.
......

The important point to make now is that, with a very few simple operations, you can simulate any other operation you want. And you've seen arithmetic, you've seen comparisons, you've seen how to define and call procedures, and you've seen how to use "if" to make decisions. This is enough to simulate anything else a computer can do. So with just that, you could write every possible computer program.

你可能感兴趣的:(Recording Dave's words in Lesson 8)