1/10
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Complete the statement so that the output prints one line for each item in sports_list, as in: 1. Hockey?
sports_list = [‘Hockey’, ‘Football’, ‘Cricket’]
for i in _____:
print(f’{i+1}. {sports_list[i]}’)
range(len(sports_list))
Which is an essential feature of a while loop having the following form?
while loop_expression:
loop_body
The loop_expression should be affected by the loop_body
What is the ending value of x?
x = 0
i = 1
while i <= 6:
x += i
i += 2
9
How many times will the print statement execute?
for i in range(1, 3):
for j in range(8, 12, 2):
print(f’{i}. {j}‘)
4
What is the best loop to use to count the number of negative values in a list of integers?
for loop
What is the output?
name = [‘Gerry’, ‘Preet’, ‘Jimin’, ‘Susan’]
index = 0
while index < len(names):
if names[index] == ‘Susan’:
break
else:
index += 1
else:
print(‘Done’)
print(index)
3
Create a range() function call that generates every even number between 20 and 30 (including both 20 and 30)?
range(20, 31, 2)
How many times will the body of the loop be executed?
number = 70
guess = 55
while number != guess:
if number > guess:
guess = guess + 10
else:
guess = guess - 1
print(f’The number is: {guess}’)
7
How many times does the following loop iterate?
i = 0
while i <= 100:
print(i)
i = i + 2
51
Complete that statement so that the final output shows how many negative values are input? Answer in the form ____ / ____.
n = 0
val = Get next input
While val is not 0:
If ___
___
val = Get next input
put n to output
val < 0 / n = n + 1
What is the output?
for j in range(2):
for k in range(4):
if (k == 2):
break
print(f’{j}{k}’, end=’ ‘)
00 01 10 11