2.2.1 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

sequence

A

Code is executed line-by-line, (one after the other) from top to bottom.

             Qty = input()
             Total = qty * price
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

branching

A
  • Branching (selection)
    Allows program to change directions depending on the outcome of a condition (Boolean expression).
    A certain block of code is run if a specific condition is met, using IF statements.
          If a > b
                  Print(“A is bigger than b”)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

iteration

A
  • Iteration (looping)
    A block of code is executed a certain number of times or while a condition is met. Iteration uses FOR, WHILE or REPEAT UNTIL loops.
    Iteration can be either:
  • Count-controlled
    Iteration is repeated a given number of times.
    for i in range (0,10):
    print i
    next i
  • Condition-controlled
    Iteration continues until a given condition is met.
    while i <= 20:
    print “Not true”;
    i=i+1
    endwhile
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

why while instead of for

A

becasue the user needs to keep enetring their password until its correct and a while loop will
continue looping until the correct password is inputted. As well as this the number of attempts isnt known

the program need sto carry on looping until the correct input is entered and a while loop will carry on looping until the correct input is eetered, a for loop will repeat only a certain number of times so it wouldnt work. As well as this the number of attempts isnt known

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

recursion

A

Is when a subroutine (often a function) call itself from within its own subroutine. Recursive function characteristics:
Contains a topping condition
For any input value other than stopping condition, the subroutine should call itself(recursion).
The stopping point should be reachable within a finite number of times.
Without these, stack overflow can occur.

Each time the function calls itself, a new stack frame is created within the call stack, where parameters, local variables and return addresses are stored. This information allows the subroutine to return to that particular point during
its execution.
A finite number of stack frames are created until the stopping condition, or base case, is reached at
which point the subroutine unwinds.

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

recursion adv and dis

A

The advantage of using recursion for certain problems is that they can be represented in fewer lines of code, which makes them less prone to errors.

Inefficient use of memory. If the subroutine calls itself too many times, there is a danger of a stack overflow,
which is when the call stack runs out of memory. This would cause the program to crash.
Another problem with recursion is that it is difficult to trace, especially with more and more function calls.

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

recursion vs iteration

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

global

A

unnecessary use of global can make program hard to test, debug and maintain.

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

local

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

difference between local and global

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

function

A

Is a block of zero that performs a specific task, taking in zero, one or more parameters and also returning a value.

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

procedure

A

Is a block of code that performs a set task, taking in zero, one or more parameters.

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

passing by reference

A

 Memory location of data is sent
 Changes are made to the original data
 Changes remain after the subprogram exits

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

passing by value

A

 A local copy of the data is used
 Data is discarded when the subprogram exits
 Does not override/change the original data

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

why by reference and not by value

A

ByRef changes the value in the variable passed.
ByRef passes the address/location [1]
ByVal only a copy of the data is passed [1]
ByVal the change would be lost when the procedure ended [1]

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

Compare the use of parameters to global variables in recursive functions.

A

Parameter allows a value to be sent to a sub-program
 Global variables can be accessed throughout the scope of the program
 Local variables can only be accessed within the scope of the sub-program it’s defined within – a parameter becomes a local variable in the function

If global, equivalent of by reference -value would be over-ridden
 Global variable takes more memory than a local variable
 In recursion, each call produces a new local
variable for num1

 Global would require altering the algorithm as the value would be over-ridden on each call
 Global would mean that memory space is kept
throughout the running of the program, not just the sub-program
 Parameter enables memory to be reallocated
 Many more memory spaces needed for parameter

17
Q

IDE

A

Integrated Development Environment (IDE), is a program which provides a set of tools to make it easier for programmers to write, develop and debug code.

Examples of IDEs include PyCharm, Eclipse, IDLE and Microsoft Visual Studio.

Common features of IDEs include:

  • Stepping
    This allows you to monitor the effect of each individual line of code by executing a single line at a time.
  • Variable watch
    Sometimes used to pinpoint errors, this is a useful feature to observe
    how the contents of a variable change in real-time through the execution of a program.
  • Breakpoint
    IDEs allow users to set a point in the program at which the program will stop. This can either be based on a condition or set to occur at a
    specific line. This can help to pinpoint where an error is occurring.
  • Source code editor
    The editor aims to make the coding process easier by providing
    features such as autocompletion of words, indentation, syntax
    highlighting and automatic bracket completion.
  • Debugging tools
    Some IDEs also provide run-time detection of errors with a guide as to where in the code they are likely to have occurred through line
    numbers and highlighting.
18
Q

Iteration adv and dis

A
19
Q

Variable

A

Identifier of a memory location used to store data