Lesson 1: Getting started with computer science using Python
introduction to the computer science using Python course
This Computer science and programming using python course will introduce you to the fundamental ideas in computing and teach you to read and write your own computer programs.
We are going to do that in the context of building a web search engine. I’m guessing everyone here has at least used a search engine before. Like Google, DuckDuckGo…
You type in what you are looking for, and voila – in literally a blink of an eye, about a tenth of a second, back come the results. This might not be enough to make you wise, but it is pretty amazing.
A goal of this class is to turn some of the magic of the search engine into something a bit more understandable. Our biggest goal tho is to learn about Computer science and programming using python.
Computer science is about how to solve problems, like building a search engine, by breaking them into smaller pieces and then precisely and mechanically describing a sequence of steps that you can use to solve each piece. And those steps can be executed by a computer.
For our search engine, the three main pieces are: finding data by crawling web pages, building an index to be able to respond quickly to search queries, and ranking pages so that we get the best result for a given query.
In this course, we will not get into everything that you need to build a search engine as powerful as Google, but we will cover the main ideas and learn a lot about computer science along the way.
The first three units will focus on building the web crawler. We will talk more about that soon. Units 4 and 5 will cover how to respond to queries quickly. And unit 6 will get into how to rank results and cover the method Google uses to rank pages, that made it so successful. But first, let’s talk about how to build a web crawler that we are going to use to get data for our search engine.
Be sure to check my instructor page to get the course as soon as it’s released.
Computer science using Python Unit 1 Overview
The goal of the first three units in this course is to build a Web crawler that will collect data from the Web for our search engine. And to learn about big ideas in Computing by doing that.
In Unit 1, we’ll get started by extracting the first link on a web page. A Web crawler finds web pages for our search engine by starting from a “seed” page and following links on that page to find other pages.
Each of those links lead to some new web page, which itself could have links that lead to other pages. As we follow those links, we’ll find more and more web pages building a collection of data that we’ll use for our search engine.
A web page is really just a chunk of text that comes from the Internet into your Web browser. We’ll talk more about how that works in Unit 4. But for now, the important thing to understand is that a link is really just a special kind of text in that web page.
When you click on a link in your browser it will direct you to a new page. And you can keep following those links as a human. What we’ll do in this Unit is write a program to extract that first link from the web page. In later units, we’ll figure out how to extract all the links and build their collection for our search engine
About quizzes in this course
We’re going to have many quizzes throughout each unit. The point of a quiz is to check that you understand what we’ve covered. Some of the quizzes will be fairly straightforward just to see if you’ve followed what we said. Other quizzes will be more challenging and require you to put together several ideas that we’ve covered.
It certainly will be valuable to try to get the answer right the first time. But they shouldn’t be stressful. They’re meant to keep you engaged in the lecture, make sure you’re understanding things.
What is programming?
Programming is really the core computer science. Most machines are designed to do just one thing. A toaster, we can do more than one thing with a toaster. But it’s pretty limited in what it can do. Everything it can do is a variation on this basic functionality that it was designed for: this basic process of putting toast in, heating it up and getting the toast to pop out.
Without a program, a computer is even less useful than a toaster. You can’t do anything without a program. The program is what tells the computer what to do. And the power of the computer is that, unlike a toaster, which is only designed to do a few things, a computer can do anything.
A computer is a universal machine. We can program it to do essentially any computation. So anything that we can imagine, anything that we can figure out how to write a program for, we can make the computer do. And what the program needs to be is a very precise sequence of steps.
The computer by itself doesn’t know how to do anything. It has a few simple instructions that it can execute. And to make a program do something useful we need to put those instructions together in a way that it does what we want.
So we can turn the computer into a web browser, into a server, into a game-playing machine, into a toaster, without anywhere to put the bread. But it can do anything we can imagine: at least any computation we want to do.
The power of the computer is that it can execute the steps super fast. So we can execute billions of instructions in one second.
The program gives us a way to tell the computer what steps to take. So there are many different languages for programming computers. The language we are going to learn in this course is the language called Python, like the snake. It is also named after Monty Python.
My students find this Python beginners Projects helpful.
The important thing about Python is that it gives us a nice high-level language that we can use to write programs. And that means instead of our program running directly on the computer, the programs we write will be an input to the Python program which runs on the computer. What Python is called an interpreter. That means it runs our programs, it interprets them, executes the programs that we wrote in Python language by running a program in a language into the computer can understand directly.
What is a program?
Now it’s time for a quiz to see if understand what a computer program is. So which of the following are computer programs? Check all that apply.
First Programming Quiz
Now we’re just going to print the number 3, and when we click Run, it will run this code and show us the result down here. And the result of printing 3, we see the output 3. We can do more interesting things. So, we can print an arithmetic expression, so I’ve got 1 plus 1. Now we run this. We see both outputs, so first we printed 3, we see the result of 1 plus 1 is 2. We can write this more clearly by having spaces. We can have spaces between the parts of our expressions. So we can have one plus one with spaces between there. that’s a little easier to read, when we run that, we see the same result. The result is still 2. And we can make more and more complex expressions, so let’s print to result of 52 times You can check that yourself to see that Python got the right answer. We can use parentheses to group expressions. So, if we use parentheses, we can do what we did before, but putting parentheses around grouping the multiplications and grouping the other multiplication. And we run this, we see the same result without the parentheses, that means the same thing as we had when we add the parentheses like this. If we put the parenthesis in different places it means something different. Now what it means is 52 times the result of adding 3 plus 12 which is that we want like this. For example if we wanted to compute the number of seconds in a year, we can compose many multiplications. So we’ll multiply 365 days times 24 hours in a day times 60 minutes in an hour times 60 seconds in a minute. We can do all those multiplications together and we get this result. Which is about 31 and a half million seconds in a year.
So now it’s time for your first programming quiz. You’ve seen enough to be able to write a Python program. And your goal is to write a Python program that prints out the number of minutes there are in seven weeks, which is the amount of time we have for this course. You’ll do that by entering your code in here. And then you can try different things. You can try running the code. See the result. And then when you’ve got an answer, you can click to submit that answer and see if it’s correct.