158k views
5 votes
What is the output of the following program?

for num in range(4):
print (num * 2)

User Jared Fine
by
3.4k points

1 Answer

4 votes

The range() function with one parameter defaults to a starting value of 0 and has an ending value of the number specified exclusive.

range(4) is all the integers between 0 and 4 not including 4.

for num in range(4):

print(num*2)

The output would be 0 2 4 6 all on separate lines.