For your hobbies - why range(3)


So all through the course i’ve been told counting starts at 0.

So it asks me to create the following:

Create a for loop that prompts the user for a hobby 3 times.

Save the result of each prompt in a hobby variable

append each one to hobbies.

print hobbies after your for loop

So I coded:

hobbies = []

for i in range(2):
hobbies = raw_input("Your hobbies: ")

print hobbies

But it only asked me to 2 times, then I checked the hint and it said to use range(3).

I thought range 2 would be asking 3 times, once at range 0, 1, 2 which would be asking 3 times.


Recall that range has up to three parrameters. The included start, the excluded stop, and the step. When only one parameter is used, it is the stop index, which as stated is exclusive, hence, range(3).

print list(range(3))    # [ 0, 1, 2 ]


Duh… Thanks. Haha late night post.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.