211k views
5 votes
Question: Python Which of the following for loops will run the loop body 5 times? for i in range(4, 0, -1) : for i in range(5, 0, -1) : for i in range(5, 1, -1) : for i in range(6, 0, -1) :

Python Which of the following for loops will run the loop body 5 times?
-for i in range(4, 0, -1) :
-for i in range(5, 0, -1) :
-for i in range(5, 1, -1) :
-for i in range(6, 0, -1)

User Mdominick
by
8.1k points

1 Answer

6 votes

Final answer:

The for loop that will run the loop body 5 times is for i in range(5, 1, -1).

Step-by-step explanation:

The correct for loop that will run the loop body 5 times is for i in range(5, 1, -1). This loop starts from 5 and decrements by 1 until it reaches 1. Since we start from 5 and stop at 1, this loop will run 5 times.

User Zamorite
by
7.9k points