answers ( graded A+ )
Which of the following statements are true? Hint: There is more than one correct answer
An indefinite loop can not be implemented with a while loop.
A for loop is always a definite loop, and a while loop is always an indefinite loop
A for loop is a shortcut for a while loop.
If the user inputs the number of times a loop should execute, it is an indefinite loop.
For loops are best suited for definite loops. - answer A for loop is a shortcut for a while loop.
For loops are best suited for definite loops.
Which of the following is true about the range function?
range(3,8) will generate the sequence 3, 4, 5, 6, 7
range(3,8) will generate the sequence 3, 4, 5, 6, 7, 8
range(8) will generate the sequence 1, 2, 3, 4, 5, 6, 7, 8
range(3,8) will generate the sequence 0, 1, 2, 3, 4, 5, 6, 7, 8 but do it 3 times. - answer
range(3,8) will generate the sequence 3, 4, 5, 6, 7
Which one of the for loop below will run 10 times?
for i in range(9):
for i in range(0, 10, 2):
for i in range(1, 10):
for i in range(10): - answer for i in range(10):
, Fill in the blanks below with either while or for.
A ________loop runs as long as a condition is true.
A ___________loop automatically increments the counting variable.
A __________loop runs for a predetermined amount of times.
A __________while loop must declare a counting variable. - answer while
for
for
while
What is wrong with the code below?
for i in range(10):
print("Hello world")
Nothing, the code is perfect.
Change the loop to for i in list(10):.
Change the loop to for i in sequence(10):.
The print statement needs to be indented. - answer The print statement needs to be indented.
Fill in the blanks below so that the loop outputs the following:
0
2
4
6