Decomposition part 1 Flashcards

1
Q

Top down approach (2)

What it helps you do+the steps

A
  • reduces the complexity of the problem becaus eyou only have to work on it a portion of a time
  • Start by outlining the major parts, then implement the solutions for each part, and debug
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

functions…..____ ______

A

does something (ex: prints sm on screen)

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

Things needed inorder to use functions: (2)

A
  1. function call
  2. function definition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Function call

A
  • actually running the function
  • ex: print(), input() ***specify the brackets dumbass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Function definition

A
  • Instructions that indicate what the finction will do when it runs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To call a function that is prefefined

A

used the brackets “()”

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

Body of a function

A
  • indented
  • the instruction or group of instructions that execute when the function is called
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

the “def” in a function

A

not executable instruction

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

The program start at the first executable instruction that is

A

not indented
*documentation dont execute

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

How do functions faciliate code reuse?

A

Once the function definition is complete (and tested reasonably) it can be called (reused many times)

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

Rather than defining instructions outside of a function, the main starting execution point can also be defined explicitly as a function:

A
  • with start functio
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The starting function (2)

A

def main ():
def start():

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

local variable

A

created within the body of a function (indented)

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

global constants

A

created outside the body of a function

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

Only things that should be gloabl are

A

constants

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

global constants are

A

not indented

17
Q

local variables are

A

idented

18
Q

The only variables that can be outside of a function

A

are constants

19
Q

Reason 1 for why we should have variables defined locally: (2)

A
  • each variables uses up a portion of memory, if the program is large then many variables may have to be declared (alot of memory may have to be allocated to store the contents of variables)
  • having them locally is good as it only stores it when necessary (minimizes memory)
20
Q

So to sum up the special thing abt defining variables locally:

A

To design a program so that memory for variables is only allocated (reserved in memory) as needed and de-allocated when they are not (the memory is free up) variables should be declared as local to a function

21
Q

The scope of an identifier is where is

A

may be acessed and used

22
Q

Tell me about locals and ending functions

A

Bc they are created in the function, once functionends, they are out of scope (no longer accepted)

23
Q

in a function, locals get used but at the end of a function, they get

A

deallocated or freed up