Quiz 5: Loops

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/10

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

11 Terms

1
New cards

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))

2
New cards

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

3
New cards

What is the ending value of x?

x = 0

i = 1

while i <= 6:

    x += i

    i += 2

9

4
New cards

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

5
New cards

What is the best loop to use to count the number of negative values in a list of integers?

for loop

6
New cards

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

7
New cards

Create a range() function call that generates every even number between 20 and 30 (including both 20 and 30)?

range(20, 31, 2)

8
New cards

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

9
New cards

How many times does the following loop iterate?

i = 0

while i <= 100:

      print(i)

      i = i + 2

51

10
New cards

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

11
New cards

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