I have two questions in "For your hobbies"



1. why there is an "u" before the hobby when i print them out?

  1. i had thought about another solution to this exercise as followed, but it didn't function. i don't know what's wrong

for i in range(3):
hobbies[i]=raw_input("enter a hobby:")
print hobbies

Replace this line with your code.


Looks to me like you just have to remove the index from hobby in the second instance as such.
hobbies = []

# Add your code below!
for i in range(3):
    hobbies=raw_input("enter a hobby")
print hobbies


The list assignment is out of range because the element you are attempting to create does not yet exist in the index. That is why we depend upon methods that permit us to append, extend or update the list.

Because length is always 1 more than the last index, it is a convenient value for the purpose of adding an item to the end of the list.

hobbies[len(hobbies)] = raw_input("Enter a hobby: ")


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