Control Flow Flashcards

1
Q

This is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated.

A

Control Flow.

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

Define iterate (verb).

A

To perfrom or utter repeatedly.

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

Com. Sci. Defintion of Iteration.

A

The repetition of a function or process in a computer program. We can use loops to execute a block of code for every iteration.

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

What is the purpose of the enumerate function?

A

A lot of times when dealing with iterators, we also get a need to keep a count of iterations. Python eases the programmers’ task by providing a built-in function enumerate() for this task.
Enumerate() method adds a counter to an iterable and returns it in a form of enumerate object. This enumerate object can then be used directly in for loops or be converted into a list of tuples using list() method.

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

Say you have a list of tuples, what technique would you use to unpack the elements of the tuples?

A

Tuple unpacking.

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

Consider mylist = [(1,2),(3,4),(5,6)], use tuple unpacking to print out the elements of the tuple.

A

for a,b in mylist:

print(a)

print(b)

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

This statement allows the for loop to run with no error from python. Without it, python will yell error. This is very useful for functions.

A

The pass statement.

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

This statement allows us to go back to the closest enclosing loop.

A

The continue statement.

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

This statement breaks the loop and very useful for while loops.

A

The break statement.

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

What is another way of saying x = x + 1 in python?

A

x += 1

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

This operator is a generator. It generates information instead of saving it.

A

The range operator.

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

How would you put a range of numbers into a list?

A

x = list(range(start,stop,step size))

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

This is a very common operator in python, it is used to add a counter to a iterable results in a tuple. Useful for strings.

A

The enumerate function.

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

Kinda opposite to the enumerate operator, this operator attaches elements of differents lists together.

A

The zip operator.

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

A quick way of checking if an item is in a list we would use what keyword?

A

-in

ex.

>> ‘x’ in [1,2,3]

<< False

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

If you would want the smallest/biggest values in your lists, what keyword would you use?

A

smallest –> min()

biggest –> max()

17
Q

What would be the line of code you would use to randomly rearrange elements?

A

from random import shuffle.

18
Q

True/False: The shuffle command shuffles in place not returning anything so we cannot save it to a variable.

A

True.

19
Q

What line of code would you use to grab a random integer between 0 & 100?

A

randiant(0,100)

This returns an output so we can save it to a variable.

20
Q

What data type does the input function return?

>> result = input(‘Enter a number here: ‘)

>> type(result)

<< ????

A

string.

To change, use int(result) or float(result).

21
Q

These are a unique way of quickly creating a list iwth python. If you find yourself using a for loop along with .append() to creat a lis, then this is an alternative!

A

List comprehensions.

22
Q

Order is different/same for if-else statements in list comprehensions as if statements.

A

different.