PY LOOP Flashcards

1
Q

Briefly describe the For Loop

A

program execution checks for iterable entities . I available then program executes it and checks for any next item. If yes then statement is executed and if no then the for loop is deemed complete and the execution continues with the next statements outside for structure.

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

______ FXN indicates the number of iterations of the for loop and used to generate a sequence and performs an action a specific number of times.

A

range

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

_____ statements inside the for loops are executed once for each value in the range

A

Indented

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

What code do we use to print a sequence in a row?

A

print(x, end=””)

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

What does the end function do?

A

used to add any string at the end of the output of the print statement in py

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

_____ can be used with the for loops to create conditional statements

A

IF

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

how can we write a code to print and sum odd numbers ?

A

the key step is for x in range (1,10,2); the 2 indicates an increment by 2 starting rom 1 which ofc will be an odd number
OR
using x%2 !=0

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

____ is used to get out of the loop

A

BREAK

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