Unit 6 : Repetition Structure Flashcards

1
Q

What is counter based looping?

A
  1. Known number of iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Examples of counter based looping ( 2 )

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

What is sentinel based looping ?

A
  1. Unknown number of iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Examples of sentinel based looping

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

What is counter based loops also called?

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

What is the difference between break and continue?

A
  1. break - ends the loop and jumps to the statement
  2. continue - ends the current iteration and jumps to the top of the loop and starts the next iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can we create a definite loop with string?

A

friends = [“Joseph”,”Glenn”,”Sally”]

for i in friends:
print(friends)
print(“Done”)

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

How can we sum inside a loop?

A

val = 0
print (“Before”, val)
for num in [9, 41, 12, 3, 74, 15] :
val = val + num
print (val, num)
print (“After”, val)

Before 0
9 9
50 41
62 12
65 3
139 74
154 15
After 154

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

How can we find the average inside a loop?

A

count = 0
sum = 0
print (“Before”, count, sum)
for value in [9, 41, 12, 3, 74, 15]:
count = count + 1
sum = sum + value
print (count, sum, value)
print (“After”, count, sum, sum / count)

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

How can we filter a loop?

A

print “Before”
for value in [9, 41, 12, 3, 74, 15]:
if value > 20:
print (“Large number”,value)
print (“After”)

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

How can we find using a boolean variable

A

found = False
print (“Before”, found)
for value in [9, 41, 12, 3, 74, 15]:
if value == 3 :
found = True
print (found, value)
print (“After”, found)

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

How can we find the smallest number?

A

smallest = None
print (“Before”)
for value in [9, 41, 12, 3, 74, 15]:
if smallest is None :
smallest = value
elif value < smallest :
smallest = value
print (smallest, value)
print (“After”, smallest)

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