Chapter 5: Repetition Flashcards

1
Q

Types of Repetition:

A
  1. Fixed Repetition
  2. Variable Repetition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The number of repetitions in FIXED REPETITION…

A

…can be determined in advance

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

the number of loops in a FIXED REPETITION is….

A

INDEPENDENT of what happens inside the loop

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

number of times a code will be repeated in VARIABLE REPETITION….

A

…CANNOT BE DETERMINED

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

Counter-controlled loops

A
  • also known as “counting loops”
  • controlled by a var whose value represents a counter
  • implement FIXED REPETITION
  • FOR & WHILE loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Event-driven loops

A
  • “Conditional loops”
  • implement VARIABLE REPETITION
  • WHILE loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

keyword break function:

A
  • immediately terminate a loop
  • continue w the next statement after loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

keyword “continue” function:

A

ends current iteration and goes to the end if the loop

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

list[-2] is the same as list[-2 + len(list1)] in the sense that both gives..

A

the SECOND LAST element in the list

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

List Slicing [start:end]

A

slice is a sublist from index start to index end-1

list1=[2,3,5,7,9,1]
list1 [2:4] #4-1
[5, 7]

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

in list:
positions != index
index = position - 1

A

extra notes

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

append()

A

adds an element at the end of list

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

count()

A

return the number of elements with specified value

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

insert()

A

adds an element at the specified POSITION

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

pop()

A

removes element at the specified position

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

remove()

A

removes element with the specified position

17
Q

sort()

A

sorts the list in ascending matter

18
Q

TUPLES

A
  • elements are FIXED
  • cannot add new elements, delete, replace nor reorder
19
Q

functions for both list and tuple

A
  1. len
  2. max()
  3. sum()
  4. min()
  5. shuffle()
20
Q

For-loop Format

A

for i in range({finalValue}):
assume initialValue is 0

({initialVal},{finalValue}):

in range({initialValue},{finalValue},{stepValue})

21
Q

Nested loop

A
  1. consist of outer loop+inner loop
  2. each time the outer is repeated, inner loop are reentered started anew