2 Flow Control Flashcards

1
Q

What are the two values of the Boolean data type? How do you write them?

A

True

False

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

What are the three Boolean operators?

A

And
Or
Not

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

Write out the truth tables of each Boolean operator (that is, every possible combination of Boolean values for the operator and what they evaluate to).

A
And: 
True and True -> True
True and False > False
False and True -> False
False and False -> False
Or:
True or True -> True
True or False -> True
False or True -> True
False or False -> False

Not:
Not True -> False
Not False -> True

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

What are the six comparison operators?

A
==
=!
<
<
>=
<=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain what a condition is and where you would use one.

A

E.g. boolean expressiones/ operators.

Conditions always evaluate down to True or False and thus decide which part of the code is executed

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

Name three flow control statement types and state what they are made of

A
  1. If
  2. While loop -> while true
  3. For loop -> for a certain number

They often start with a condition, which is always followed by the clause (block of code)

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

What keys can you press if your program is stuck in an infinite loop?

A

ctrl + c

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

What is the difference between break and continue?

A

Both are used inside loops.
Continue: program execution jumps back to the start of the loop
Break: program execution jumps out of the loop

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

What does this code evaluate to?

x = [[1, 2], [3, 4]]
for x in x:
for x in x:
print(x)

How could you write this code in one line?

A

x = [[1, 2], [3, 4]]
for x in x:
for x in x:
print(x)

Evaluates to:
1
2
3
4

One line:
x for x in x for x in x

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

numbers=[‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’]
letters=[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’]

How can you create a list, that has as many list as there are numbers, and as many values as there

A

numbers=[‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’]
letters=[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’]

spam = []
for nr in numbers:
    spam.append(list())
    for letter in letters:
        spam[-1].append(nr + letter)        
print(spam)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly