MIT 6.00 Week 2 Flashcards

1
Q

What guarantees that a loop will end?

A

A decrementing function

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

What characteristics are required of a decrementing function?

A

1) It maps a set of program variables to an integer.
2) It starts with a non-negative value.
3) It terminates when the value < 0.
4) It decreases each iteration.

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

What is “brute force” problem solving?

A

Exhaustive enumeration

Determining the range of values that an answer could be, and checking each value individually, in order, until you find the correct answer.

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

What is the syntax of a for loop in Python?

A

for variable in (something):

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

what is the syntax for the range function?

A

range(start, stop, increment)
start is inclusive
stop is non inclusive

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

What do we do when an exact answer cannot be ensured?

A

Use approximation.

Determine what answer will be close enough that we are satisfied, and search for an answer within that range.

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

What is a faster type of search than exhaustive enumeration, and how does it work?

A

Bisection Search:

1) Determine a range within the answer can be found
2) Test the middle of the range. If it is too high, make it the new upper bound. If it is too low, make it the new lower bound.
3) Test the answer that is the middle of the new range.
4) Repeat until the answer, or an acceptable approximation, is found.

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

What advantages does the use of functions provide?

A

1) Decomposition

2) Abstraction

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

What do we mean by decomposition?

A

Structure is created. The modules created by functions are self-contained and reusable.

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

What doe we mean by abstraction?

A

Details are suppressed when they are unimportant or distracting.

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

How do we create a function?

A
def functionName(parameter, parameter,...):
     Function Body
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we get a value back from a function?

A

the return keyword

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

What happens if you do not use return in a function?

A

It will return the none data type

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

What is the term for calling on a function?

A

Invoking

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

What is the written description and explanation of a function called?

A

The specification

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

What should be included in specification?

A

The purpose/effect of the function, and the parameters it takes.

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

What is the term for the parameter found in the definition of a function?

A

The formal parameter

or

parameter

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

What is the term for a value passed into a function?

A

The actual parameter

or

argument

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

What is scope?

A

The matching of names to objects.

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

What keyword will check for a true/false value, and terminate the program is the value is false?

A

assert

21
Q

Planning for bad inputs is:

A

Defensive programming

22
Q

When are scopes created?

A

When a function is run, not when it is defined.

23
Q

Another term for scope is:

A

A stack frame

24
Q

The list of scopes and their relative distance to the main scope:

A

The stack

25
Q

When something is removed from the stack, we:

A

pop the stack

26
Q

What is the relationship of variables in one scope to the variables of another scope?

A

They are discreet.

This is more complicated than it is currently being presented.

27
Q

What happens if a string is used in a for loop?

A

The variable will be assigned each character in the string, in order, and run through the loop.

28
Q

How do you find a character in a certain position within a string?

A

s[#:#]

where “s” is the name of the variable the string is in, the first # is the position of the character you want to start with, and the second # is the end character.

The first number is inclusive, starting at 0. The second number is exclusive.

29
Q

How do you find a certain character in a string?

A

variableName.find(‘a’)

‘a’ is the character you are looking for. The result is the position of the character in the string, starting with 0.

30
Q

How do you find a list of everything you can do with a data type, without descriptions?

A

dir(data_type)

31
Q

How do you find a definition of a keyword from within IDLE?

A

help(data_type.keyword)

32
Q

how do you find a list of everything you can do with a data type, with descriptions?

A

help(data_type)

33
Q

Define a tuple:

A

a non-scalar data type that can hold many things

34
Q

what is the literal syntax of a tuple?

A

(element, element)

35
Q

How can the individual parts of a tuple be accessed?

A

By using indices

36
Q

what are two ways to print an individual element of a tuple?

A

print tuple_name[x]
Where x is the index position you want to print, starting with 0

print tuple_name[-x]
Where -x is the index position you want to print, reading from right to left, starting with -1 as the last element in the tuple.

37
Q

What kind of data structure only houses one kind of data type?

A

A homogenous data type

38
Q

What kind of data structure houses multiple different data types?

A

A heterogenous data structure.

39
Q

Tuples can hold tuples

A

tuple_name1(tuple_name2(x, y), z)

40
Q

What happens if you print the tuple itself?

A

You will print a literal representation of the tuple, as you see it.

if the tuple is (1, 2, ‘a’), the program will print:

(1, 2, ‘a’)

41
Q

A data type whose elements cannot be changed is an:

A

immutable data type

42
Q

Are tuples an immutable data type?

A

yes

43
Q

What are the defaults when you leave blanks while choosing sections of an index? i.e. [:#] or [#:]

A

The default start is 0

the default end is the last element of the index

44
Q

What happens when you add a tuple to a tuple?

A

The elements of the second tuple are added, in order, to the end of the first tuple.

45
Q

What is a common mistake when writing a tuple of one element?

A

Forgetting the ‘,’

For example (‘a’,) is a tuple, whereas (‘a’) is not. The second is simply regarded as more important for order of operations.

46
Q

What keyword kicks you out of a loop?

A

break

47
Q

What is a function, roughly?

A

A named, pre-written piece of code that takes inputs and gives outputs.

48
Q

What is another term for the specification?

A

The doc string

49
Q

What is another term for invoking a function?

A

Calling the function