186k views
5 votes
What is the output of the loop for count in range(5):print(count, end = " ")?

a) 0 1 2 3 4
b) 1 2 3 4
c) 5 6 7 8 9
d) 1 2 3 4 5

User Lysol
by
8.4k points

1 Answer

4 votes

The loop with the range(5) function will output '0 1 2 3 4 ' with each number separated by a space, due to the print statement's end parameter.

The question asks about the output of a given Python for loop with a specific range function and a print statement. The range(5) function generates a sequence of numbers from 0 to 4, which results in the loop iterating five times. The print function is called with the argument end=' ', which causes all the outputs to be printed on the same line, separated by a space, rather than each on a new line.

In conclusion, the loop will print out the numbers from 0 up to, but not including, 5. The numbers will be spaced out on the same line due to the end=' ' argument.

User Alapshin
by
7.2k points