MIT 6.00 Week 2 Flashcards Preview

Programming > MIT 6.00 Week 2 > Flashcards

Flashcards in MIT 6.00 Week 2 Deck (49):
1

What guarantees that a loop will end?

A decrementing function

2

What characteristics are required of a decrementing function?

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.

3

What is "brute force" problem solving?

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.

4

What is the syntax of a for loop in Python?

for variable in (something):

5

what is the syntax for the range function?

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

6

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

Use approximation.

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

7

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

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.

8

What advantages does the use of functions provide?

1) Decomposition

2) Abstraction

9

What do we mean by decomposition?

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

10

What doe we mean by abstraction?

Details are suppressed when they are unimportant or distracting.

11

How do we create a function?

def functionName(parameter, parameter,...):
Function Body

12

How do we get a value back from a function?

the return keyword

13

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

It will return the none data type

14

What is the term for calling on a function?

Invoking

15

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

The specification

16

What should be included in specification?

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

17

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

The formal parameter

or

parameter

18

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

The actual parameter

or

argument

19

What is scope?

The matching of names to objects.

20

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

assert

21

Planning for bad inputs is:

Defensive programming

22

When are scopes created?

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

23

Another term for scope is:

A stack frame

24

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

The stack

25

When something is removed from the stack, we:

pop the stack

26

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

They are discreet.

This is more complicated than it is currently being presented.

27

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

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

28

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

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

How do you find a certain character in a string?

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

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

dir(data_type)

31

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

help(data_type.keyword)

32

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

help(data_type)

33

Define a tuple:

a non-scalar data type that can hold many things

34

what is the literal syntax of a tuple?

(element, element)

35

How can the individual parts of a tuple be accessed?

By using indices

36

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

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

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

A homogenous data type

38

What kind of data structure houses multiple different data types?

A heterogenous data structure.

39

Tuples can hold tuples

tuple_name1(tuple_name2(x, y), z)

40

What happens if you print the tuple itself?

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

A data type whose elements cannot be changed is an:

immutable data type

42

Are tuples an immutable data type?

yes

43

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

The default start is 0
the default end is the last element of the index

44

What happens when you add a tuple to a tuple?

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

45

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

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

What keyword kicks you out of a loop?

break

47

What is a function, roughly?

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

48

What is another term for the specification?

The doc string

49

What is another term for invoking a function?

Calling the function