Unit 1 Flashcards

1
Q

What is a web crawler? How does it work?

A

A web crawler is a program that collects content from the web. A web crawler finds web pages by starting from a seed page and where it collects the desired content plus all of the links on the page. It then follows the links to other pages, collecting content a links, following those links, and repeating the process over and over.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a computer?

A

A machine that can execute a program. With the right program, a computer can do any mechanical computation you can imagine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a program?

A

A program is instructions that tell the computer what to do by describing a very precise sequences of steps. Since the computer is just a machine, the program must give the steps in a way that can be executed mechanically. That is, the program can be followed without any thought.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a programming language?

A

A programming language is a language designed for producing computer programs. A good programming language makes it easy for humans to read and write programs that can be executed by a computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Python?

A

Python is a programming language. The programs written in Python will be the input to the Python interpreter, which is a program that runs on the computer. The Python interpreter reads our programs and executes them by following the rules of the Python language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an expression in Python? What is one rule of the Python grammar for making expressions?

A

An expression is something that has a value. One rule of the Python grammar for making expressions is:

Expression ==> Expression Operator Expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Expression ==> Expression Operator Expression
What type of definition is this an example of? What are the two rules you need to make this type of definition and why is this type of definition important?

A

This is an example of a recursive definition. To make a good recursive definition you need at least two rules:

  1. A rule that defines something in with terms referring to itself.
    Expression ==> Expression Operator Expression
  2. A rule that defines that thing in terms of something else that we already know.
    Expression ==> Number
    Number ==> 0, 1, 2, . . .
    Operator ==> +

Recursive definitions are a very powerful idea in computer science. They allow us to define infinitely many things using a few simple rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does Python perform integer division?

A

When you divide an integer (a number without decimals) by another integer Python performs integer division, which means it will ignore the decimal part of the answer. To force Python to give an answer with a decimal you have to make one of the number into a decimal, or a floating point number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the processor? Why must processors get smaller as they get faster?

A

A processor is the part of the computer that carries out the steps specified in a computer program. Sometimes called the central processing unit, or CPU. As processors get faster they execute more cycles each second. The electric current, moving at the speed of light, must run through the entire processor each cycle. If the processor is a 2.7 GHz processor, electricity will need to cycle through the processor 2.7 billion times each second. So each cycle will need to be 1/2,700,000,000 (one-two-billion-seven-hundred-millionth) of a second long. In that length of time, light will travel about 11 cm. If the processor was any bigger than that size, the electric current could not cycle through the entire processor before the next cycle needed to being. This would limit the processor speed to something slow enough to account for the distance the light needed to travel each cycle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a variable? What does Python use as variables?

A

A variable is a name that refers to a value. In Python, we can use any sequence of letters and numbers and underscores ( _ ) we want to make a variable name, so long as it does not start with a number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What do you use to introduce a new variable? What does executing this thing cause to happen?

A

You use assignment statements to introduce a new variable. After executing an assignment expression, the name refers to the value of the expression on the right side of the assignment.

speed_of_light = 299792458

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a special characteristic of variable’s reference property?

A

The value of a variable can change. When a variable name is used, it always refers to the last value assigned to that variable. Since the value that a variable refers to can change, that same exact expression can have different values at the different times it is executed.
Remember that the “ = “ means assigned more than equals in Python. Equals is show with “==”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a string?

A

A string is a sequence of characters surrounded by quotes; either single or double.

‘This is a string’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How is the plus operator used with strings? How is the multiplication operator used with strings?

A

The plus operator concatenates two strings and the multiplication operator can replicate a string multiple times, like when printing.

print ‘hel’ + ‘lo’
hello

print ‘hello’ * 3
hellohellohello

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is string indexing? What does a negative number do with string indexing?

A

Indexing is the system used for selecting sub-sequences from strings. Square brackets ( […] ) are used to specify which part of the string you want to select.

[]
print ‘string’[0]
s

Negative numbers cause the index to start counting from the back of the string.
print ‘string’[2] + ‘string’[-1]
tg

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you select a sub sequence of characters from a string?

A

You select a sub-sequence of a string by designating a starting position and an end position.

{ : ]

print ‘string’[2:4]
rin
print ‘string’[3:]
ng

17
Q

What is the find method? What does it operate on?

A

The find method is a build in operation, or method, provided by Python, that operates on strings. The output of find is the position of the string is where the specified sub-string is found.

.find()

print ‘string’.find(‘in’)
4

18
Q

What happens if the find method cannot locate the target string within the search string?

A

The out put is -1 if the target string is not found anywhere in the search string.

19
Q

How are numbers used as an argument in the find method?

A

The number input is the position in the search string where find will start looking for the target string. So the output is the number giving the position of the first occurrence of the target string in the search string at or after the number input position. If there is no occurrence at or after that position, the output is -1.

20
Q

How can a web page be thought of in relation to strings?

A

A web page is really just a long string of characters. Your browser renders the web page in a way that looks more attractive than just the string of characters.

21
Q

To find links with a web crawler, what sub-section of the web page string does the find method need to look for?

A

Web crawlers can find links by looking for the anchor tags in the HTML. It looks like this:

<a></a>

</a><a></a>

To build a web crawler, you want to find all of the link URLs on each web page, keep track of them, and follow each of them to find more content on the web.</a>