Lecture 6 Flashcards

(16 cards)

1
Q

Loops definition

A

Loops are used to repeat certain sections of code a defined number of times

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

What do loops allow us to do?

A

-automate repetitive tasks without having to rewrite code
-Add flexibility/adaptability to code when the number of times a code should be repeated is dynamic
-embedded automation systems operate as loops

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

What do for loops do

A

The for loop in Python is the concept of an editable which are data structures that contain multiple elements which can be retrieved one at a time.

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

What type of data structures are iterable?

A

Lists
Tuples
Sets
Dictionaries

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

For loop syntax

A

For <var> in <iterable>:
<code>
<code></code></code></iterable></var>

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

Given my_dict={“a”:1, “b”:2}
For x in my_dict:
print(x, “:”, my_dict[x])

A

Output =
a:1
b:2

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

Given my_dict={“a”:1, “b”:2}
For x in my_dict.values():
print(x)

A

Output:
1
2

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

Given my_dict={“a”:1, “b”:2}
For x, y in my_dict.items():
print(x, “:”, y)

A

Output:
a:1
b:2

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

How to break loops

A

Add the break command.
The loop will stop when this line is encountered, even if there are more things to iterate

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

Skipping the remainder of the current iteration, but continuing on with the next iteration command

A

Continue

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

Range command

A

range(start, stop, step)
Will return an editable that is a sequence of numbers from start to stop incremented by step .

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

Start, stop and step for range command

A

Start is optional and when excluded is default zero
Step is optional and when excluded is default one it may also be negative
An empty sequence is returned if start is greater than stop

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

Nested loop

A

Is a loop inside of a loop

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

While loops

A

While loops execute a section of coda as long as a condition is true. While loops, unlike four loops are almost the same as other other programming languages.

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

While loop syntax

A

while <condition>:
<code>
<code></code></code></condition>

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