19.7k views
1 vote
Which of the following does not properly nest control structures?

answer choices
O for i in range(3):
for j in range(6):
print(j)

O for i in range(3):
if i > 2:
break
else:
print(i)

O count = 0
if count < 10:
for i in range(3):
print(count)
count = count + 1

O count = 10
for i in range(3):
if count > 0:
print(i)
else:
print(count)

1 Answer

4 votes

Answer:

The option that does not properly nest control structures is:

```

count = 0

if count < 10:

for i in range(3):

print(count)

count = count + 1

```

The `if` statement is not properly nested within the `for` loop. As it is currently written, the `if` statement will only be evaluated once, before the `for` loop executes. This means that if `count` is less than 10 initially, then the `for` loop will always execute three times, regardless of the value of `count`.

To properly nest the control structures, the `if` statement should be inside the `for` loop, like this:

```

count = 0

for i in range(3):

if count < 10:

print(count)

count = count + 1

else:

break

```

This way, the `if` statement is evaluated for each iteration of the `for` loop, and the loop will terminate if `count` becomes larger than 10.

User Ashraful
by
8.0k points

No related questions found