W4 - LOOPS Flashcards

1
Q

What is an action?

A

a set of statements which are grouped together, usually by indentation and are the “body” of a loop or conditional. it is literally the action that is being done if ____ is true or false or whatevs

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

how does range() function

A

range(n), used to sequence of integers ranging from 0, 1, 2, 3…. up until n-1 (think indices!)

if range is (i, j) starts sequence at i, then progresses by 1 to j-1

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

what will:
for i in range(3, 5):
print(i)
print?

A

3
4

range can be used as, well, a range!

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

break down the header statement of this for loop:
for i in range(5):

A

the “for i” establishes i as an iterator variable. in python, this setup automatically sets i to each value in the SEQUENCE VARIABLE (going left to right one by one) created by range (0, 1, 2, 3, 4 in this case).

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

what will this print?
ran = [1, 2, 5, 9, 13]
for i in ran:
print(i, end = ‘ ‘)

A

1 2 5 9 13

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

alphabet = “abcd”
for i in alphabet:
print(i, end = “ “)
print(i)

what will the above print?

A

a b c d d

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

create a while loop that adds from x = 0 to x = 5 then breaks off to print x = 5 when x = 5 using an else

A

x = 0
while x < 5:
x=x+1
else:
print(“x=5”)

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