178k views
4 votes
Write a loop to print 56 to 70 inclusive (this means it should include both 56 and 70). The output should all be written out on the same line.

a) for i in range(56, 71): print(i, end=" ")
b) for i in range(55, 70): print(i, end=" ")
c) for i in range(57, 71): print(i, end=" ")
d) for i in range(56, 70): print(i, end=" ")

User Bulent
by
8.5k points

1 Answer

0 votes

Final answer:

The correct loop to print the numbers from 56 to 70 inclusive on the same line is 'for i in range(56, 71): print(i, end=" ")'. The range function includes the first number but excludes the last, hence 71 ensures 70 is printed.

Step-by-step explanation:

The correct way to write a loop that prints the numbers from 56 to 70 inclusive on the same line, using Python's range function, is option a). Here's the correct loop: for i in range(56 print(i, end=" ")

This loop starts at 56 and ends at 70 because the range function includes the start number but excludes the stop number, so we use 71 to include 70 in our loop. Options b), c), and d) do not print the required sequence correctly because they either start or end with the wrong numbers.

User Editate
by
8.5k points