Python loops Flashcards
Types of python loops
- While loops
2. For loops
While loops repeatedly execute a statement or block of statements as long as the condition is _____
TRUE
When the condition is _____ the loop terminates and the line immediately after the loop in a program is executed
FALSE
Python uses indentation as its method of _______ statements
to indicate a block/grouping of code
All the statements indented by the same number of character spaces after a programming construct are considered to be part of a single _____ of code
block
count = 0
while (count < 3):
count = count + 1
Identify the
a) initializing of the counter variable
b) checking of condition
c) update
d) sentinel
a) initialize count - count =0
b) check condition - while (count<3)
c) update - count = count +1
d) sentinel - 3
count = 0
while (count < 3):
count = count + 1
print(“Hello Geek”)
What would be the output?
Hello Geek
Hello Geek
Hello Geek
The _____ clause is only executed when your while condition becomes false
else
____ loops are used for sequential traversal. For example: traversing a list or string or array etc.
For
In Python, the counter is not the letter __
C
The _____ function gives a sequence of numbers based on the start and stop index given
Range
In case the start index is not given, the index is considered as __, and it will increment the value by 1 till the stop index.
(range function)
Eg. for i in range(10):
print(i, end =” “)
0
range(5)
What would the output be?
0,1,2,3,4
n = 4
for i in range(0, n):
print(i)
What is printed?
Output 0 1 2 3
_______ iterations are for when you DON’T know how many times to do the action. They require you to initialize, check and update on your own
unbounded