Why Does the Exercise Ask for One Hobby and Print it Three Times?

why does the code academy solution ask for one hobby and then print it 3 times?

1 Like

Hi @jobseeker69,

Using a loop means you don’t have to write the code to get input and append it to the list for each hobby. If you wanted to ask for the user’s 5 favorite hobbies at some point, it would be easier to change the length of the range() than it would be to write more raw_input() lines for each additional hobby.

I found this confusing too. I was expecting three inputs, rather than one input and three options.

Generally, if you’re repeating an action several times, it’s best to put it in a loop. You’ll get used to doing that as you program more.

I would have it loop using range(3), and it would prompt me once, let me type my response, than after I did that, it would prompt me twice more and print out that initial hobby 3 times without letting me enter anything the other two times, as if the raw_input() was not working and just printing the prompt and moving on. However, I didn’t see anything wrong with the code and codecademy said I had it correct. (A similar issue also occurred in the lesson “For Your Health” just before.)